Skip to content

Commit

Permalink
Use GetMessage instead of PeekMessage see if it helps with high cpu
Browse files Browse the repository at this point in the history
Without causing delays.
Removed Sleep(0) from the message pump loop.
resolves #5
  • Loading branch information
LiamKarlMitchell committed Aug 2, 2022
1 parent c3d731c commit 802ff7f
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 12 deletions.
6 changes: 3 additions & 3 deletions InhibitWindowsEvents.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down
71 changes: 71 additions & 0 deletions InhibitWindowsEvents/InhibitWindowsEvents.rc
Original file line number Diff line number Diff line change
@@ -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

9 changes: 9 additions & 0 deletions InhibitWindowsEvents/InhibitWindowsEvents.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@
<ItemGroup>
<ClCompile Include="Source.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="InhibitWindowsEvents.rc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<Image Include="app.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
15 changes: 15 additions & 0 deletions InhibitWindowsEvents/InhibitWindowsEvents.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,19 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="InhibitWindowsEvents.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="app.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>
18 changes: 9 additions & 9 deletions InhibitWindowsEvents/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include <windows.h>
#include <stdio.h>

#include "resource.h"

using namespace std;

HHOOK llMouseHook = NULL;
HHOOK llKeyboardHook = NULL;
bool EnableHooks = true;
Expand Down Expand Up @@ -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.");
Expand Down
Binary file added InhibitWindowsEvents/app.ico
Binary file not shown.
16 changes: 16 additions & 0 deletions InhibitWindowsEvents/resource.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 802ff7f

Please sign in to comment.