Skip to content

Commit

Permalink
numlock: initial code
Browse files Browse the repository at this point in the history
  • Loading branch information
myfreeer authored May 13, 2017
1 parent 0a05401 commit 123d522
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions numlock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <windows.h>

void SetNumLock(BOOL bState) {
BYTE keyState[256];

GetKeyboardState((LPBYTE) & keyState);
if ((bState && !(keyState[VK_NUMLOCK] & 1)) ||
(!bState && (keyState[VK_NUMLOCK] & 1))) {
// Simulate a key press
keybd_event(VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0);

// Simulate a key release
keybd_event(VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
if (lstrlen(lpCmdLine) > 0) {
SetNumLock(FALSE);
} else {
SetNumLock(TRUE);
}
return 0;
}

0 comments on commit 123d522

Please sign in to comment.