From 802ff7faf491d7466f16e038c153e50b2ce97116 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 2 Aug 2022 20:03:11 +1200 Subject: [PATCH] Use GetMessage instead of PeekMessage see if it helps with high cpu Without causing delays. Removed Sleep(0) from the message pump loop. resolves #5 --- InhibitWindowsEvents.sln | 6 +- InhibitWindowsEvents/InhibitWindowsEvents.rc | 71 ++++++++++++++++++ .../InhibitWindowsEvents.vcxproj | 9 +++ .../InhibitWindowsEvents.vcxproj.filters | 15 ++++ InhibitWindowsEvents/Source.cpp | 18 ++--- InhibitWindowsEvents/app.ico | Bin 0 -> 15086 bytes InhibitWindowsEvents/resource.h | 16 ++++ 7 files changed, 123 insertions(+), 12 deletions(-) create mode 100644 InhibitWindowsEvents/InhibitWindowsEvents.rc create mode 100644 InhibitWindowsEvents/app.ico create mode 100644 InhibitWindowsEvents/resource.h diff --git a/InhibitWindowsEvents.sln b/InhibitWindowsEvents.sln index 425795d..ac8ae3a 100644 --- a/InhibitWindowsEvents.sln +++ b/InhibitWindowsEvents.sln @@ -1,7 +1,7 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.25920.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31424.327 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InhibitWindowsEvents", "InhibitWindowsEvents\InhibitWindowsEvents.vcxproj", "{97A38EC2-3DBC-4C5A-9799-9BBCF7CE5E0E}" EndProject diff --git a/InhibitWindowsEvents/InhibitWindowsEvents.rc b/InhibitWindowsEvents/InhibitWindowsEvents.rc new file mode 100644 index 0000000..dd4d830 --- /dev/null +++ b/InhibitWindowsEvents/InhibitWindowsEvents.rc @@ -0,0 +1,71 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United Kingdom) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK +#pragma code_page(1252) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_ICON1 ICON "app.ico" + +#endif // English (United Kingdom) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/InhibitWindowsEvents/InhibitWindowsEvents.vcxproj b/InhibitWindowsEvents/InhibitWindowsEvents.vcxproj index d6780ad..b9284d5 100644 --- a/InhibitWindowsEvents/InhibitWindowsEvents.vcxproj +++ b/InhibitWindowsEvents/InhibitWindowsEvents.vcxproj @@ -140,6 +140,15 @@ + + + + + + + + + diff --git a/InhibitWindowsEvents/InhibitWindowsEvents.vcxproj.filters b/InhibitWindowsEvents/InhibitWindowsEvents.vcxproj.filters index 4a8dc32..38e773c 100644 --- a/InhibitWindowsEvents/InhibitWindowsEvents.vcxproj.filters +++ b/InhibitWindowsEvents/InhibitWindowsEvents.vcxproj.filters @@ -19,4 +19,19 @@ Source Files + + + Resource Files + + + + + Header Files + + + + + Resource Files + + \ No newline at end of file diff --git a/InhibitWindowsEvents/Source.cpp b/InhibitWindowsEvents/Source.cpp index d5dd53b..ffe7cf3 100644 --- a/InhibitWindowsEvents/Source.cpp +++ b/InhibitWindowsEvents/Source.cpp @@ -2,6 +2,10 @@ #include #include +#include "resource.h" + +using namespace std; + HHOOK llMouseHook = NULL; HHOOK llKeyboardHook = NULL; bool EnableHooks = true; @@ -169,17 +173,13 @@ WinMain(HINSTANCE hInstance, // handle to current instance llMouseHook = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMouseProc, hInstance, 0); llKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hInstance, 0); - MSG msg; - msg.message = NULL; // Just in case msg is not 0'd out by default. - // This is the message pump loop. // Needed or the system will go very unresponsive. - while (msg.message != WM_QUIT) { //while we do not close our application - if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - Sleep(0); + MSG msg; + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); } puts("Exiting."); diff --git a/InhibitWindowsEvents/app.ico b/InhibitWindowsEvents/app.ico new file mode 100644 index 0000000000000000000000000000000000000000..8a29bd0a6be98c9a04939f9fd2e0b6b0ba214d56 GIT binary patch literal 15086 zcmd6u37C&n-^b6)&@>suWGf8W6|!W>WU4{-ND|q1ii|9&nCXct=@Ck)&`3RbuF~@4 z?drMY!DDZ+)tkyvBfLT}V{2s0{eHgZf8T%iEN1>QJn!|M%XiLwmfv#D`JLa{{)`DT z5$5{q4WXJDRm_;?`l=R4|DF6d$-C_~H(kq^_T`MJOHw4&K$!i@2lY0T3V>9O;E=Y6 zB(4GO0QZ0da3{D0L<6^;pWMrHZlb&mXap(%)xQqJ0910~-8h2SWe}vTL*4*TK2YYB zt6H$mHGI=j=XT)ouw|7=OW$gs83+e1e}5F@(~$B8fjW-b8*j{(vc^1I)tE1O7_*f& z-$GCI^Am>!5|)Q#t54`@+gI>QpzZU%FlOQrV`lzl%-q3~CYfR>DJ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H8Ev{1 zvHZ5q%{l59H7P!EFO@6z{P~?bzs>cQmVfU%&ZbS9{^V_Y+^A8QMYdq|t&X1Z{}luJ z+OyPKeBT&IXCo+5B0OAjV(z{D_6}=!3oCU0^ZUU}-o__C@(9-u*@D%-Eqcxanq!pO z-?!;}mJmp1BPc?``rYe!O`bxqL5J$2GOy4_b(8_b?&*%RRpG$c%cI?<8{h!W5|5E6<2(%37Dm|_K zb&0j+Tm>7_Qc=1d@7UWXPfoe4^7cQOWj>?N^iEHaiO!E_CwR zpR#{Q=eI>YFYO#etb%S%5s zMDO|ZbG9}qk(QR`FmJb@Qu!GDOfR5+H)74(Jnp5uHdy_&24i&g{@OQ3ygH%9QBhH< zcrCv#n#S)Q()D`-f6%#Cw!_-s&vy8&fb;UpFQ>Bawj1a0@Pn|icUFHR_T7zKP7m7# zt3n&(cx^`EvfU`)kdA^$-15RGybp#mXuP-xRPF3lgGrzUxC-sCyo#0qL47Ry z5M4(w5i9}f?}4BaP@6*5-H@0V`#cZ_<2)C5;5t_cz&^*0H;`90uHhrz+0#3f1xn~>1o7U zj5(N*52@+Ok?5{HPgm)lZ|mF#IagJ zl$PQ)&a&}b=W;Ri;J-ulk+;PkOFz+hF?y#fO`Jv?Mtf+638Q_P@lNtJv^Oi($!JUa l9h#MzMEoqVL%hy$o>80@pBbqb-E4pI4Ga2vU4;7me*qV1LWlqW literal 0 HcmV?d00001 diff --git a/InhibitWindowsEvents/resource.h b/InhibitWindowsEvents/resource.h new file mode 100644 index 0000000..61e4ed2 --- /dev/null +++ b/InhibitWindowsEvents/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by InhibitWindowsEvents.rc +// +#define IDI_ICON1 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif