generated from kitswas/CPP-project-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "simulate.hpp" | ||
|
||
bool blockExternalInput() | ||
{ | ||
return BlockInput(TRUE); | ||
} | ||
|
||
bool unblockExternalInput() | ||
{ | ||
return BlockInput(FALSE); | ||
} | ||
|
||
void clearExistingInput() | ||
{ | ||
// Get the keyboard state | ||
BYTE keyboardState[256]; | ||
GetKeyboardState(keyboardState); | ||
|
||
// Cancel any existing input | ||
// Iterates through all keys, checking if they are down, and releasing them if they are | ||
for (int i = 0; i < 256; i++) | ||
{ | ||
if (keyboardState[i] & 0x80) | ||
{ | ||
// Release the key | ||
keyUp(i); | ||
} | ||
// ostream_here << "0X" << std::hex << i << std::dec << "(" << i << ")" | ||
// << "is" << (keyboardState[i] & 0x80 ? "down" : "up"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "keyboardSim.hpp" | ||
#include "mouseSim.hpp" | ||
|
||
/** This function is used to block input from external devices. | ||
* It stops keyboard and mouse input events from reaching applications. | ||
* It is used to prevent the user from accidentally interfering with the program. | ||
* | ||
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-blockinput | ||
* | ||
* @note **Emergency Exit:** <kbd>CTRL</kbd> + <kbd>ALT</kbd> + <kbd>DEL</kbd> | ||
* @see @link unblockExternalInput() | ||
*/ | ||
bool blockExternalInput(); | ||
|
||
/** This function is used to unblock input from external devices. | ||
* It allows keyboard and mouse input events to reach applications again. | ||
* | ||
* @see @link blockExternalInput() | ||
*/ | ||
bool unblockExternalInput(); | ||
|
||
void clearExistingInput(); |