Created
March 16, 2019 17:00
-
-
Save mustafat0k/eb6b116ee58d9779d7f2700de53c84d5 to your computer and use it in GitHub Desktop.
Capslock keyboard hook
This file contains hidden or 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
#include <windows.h> | |
void GenerateKey(int vk, BOOL bExtended); | |
int main() | |
{ | |
GenerateKey('A', FALSE); | |
GenerateKey(VK_CAPITAL, TRUE); | |
GenerateKey('A', FALSE); | |
for (;;) { | |
if (GetKeyState(VK_CAPITAL) == TRUE) { | |
GenerateKey('Z', TRUE); | |
GenerateKey('1', TRUE); | |
Sleep(300); | |
} | |
} | |
//mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); } | |
} | |
void GenerateKey(int vk, BOOL bExtended) | |
{ | |
KEYBDINPUT kb = { 0 }; | |
INPUT Input = { 0 }; | |
// generate down | |
if (bExtended) | |
kb.dwFlags = KEYEVENTF_EXTENDEDKEY; | |
kb.wVk = vk; | |
Input.type = INPUT_KEYBOARD; | |
Input.ki = kb; | |
::SendInput(1, &Input, sizeof(Input)); | |
// generate up | |
::ZeroMemory(&kb, sizeof(KEYBDINPUT)); | |
::ZeroMemory(&Input, sizeof(INPUT)); | |
kb.dwFlags = KEYEVENTF_KEYUP; | |
if (bExtended) | |
kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; | |
kb.wVk = vk; | |
Input.type = INPUT_KEYBOARD; | |
Input.ki = kb; | |
::SendInput(1, &Input, sizeof(Input)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment