Low-Level Keyboard Input Detection
-
Hey there, I am writing an software that should be able to detect all keyboard inputs by the user. i.e., both hardware and software/on-screen keyboard. This software is going to be written in a platform independent way and supposed to run on Windows, Linux, Android & iOS. The idea is to capture the keyboard inputs from a low level, there by making sure that it doesn't miss any inputs even if it's a on-screen keyboard like in a mobile device. I am looking at possible open source libraries that can be used. Anyone got any good ideas on what to use? Thanks in advance!
-
Hey there, I am writing an software that should be able to detect all keyboard inputs by the user. i.e., both hardware and software/on-screen keyboard. This software is going to be written in a platform independent way and supposed to run on Windows, Linux, Android & iOS. The idea is to capture the keyboard inputs from a low level, there by making sure that it doesn't miss any inputs even if it's a on-screen keyboard like in a mobile device. I am looking at possible open source libraries that can be used. Anyone got any good ideas on what to use? Thanks in advance!
-
Hey there, I am writing an software that should be able to detect all keyboard inputs by the user. i.e., both hardware and software/on-screen keyboard. This software is going to be written in a platform independent way and supposed to run on Windows, Linux, Android & iOS. The idea is to capture the keyboard inputs from a low level, there by making sure that it doesn't miss any inputs even if it's a on-screen keyboard like in a mobile device. I am looking at possible open source libraries that can be used. Anyone got any good ideas on what to use? Thanks in advance!
-
Hey there, I am writing an software that should be able to detect all keyboard inputs by the user. i.e., both hardware and software/on-screen keyboard. This software is going to be written in a platform independent way and supposed to run on Windows, Linux, Android & iOS. The idea is to capture the keyboard inputs from a low level, there by making sure that it doesn't miss any inputs even if it's a on-screen keyboard like in a mobile device. I am looking at possible open source libraries that can be used. Anyone got any good ideas on what to use? Thanks in advance!
For Windows, here is a global key hook example, prints pressed keycodes to the console. It even works when it's in the background. And this is a Windows discussion board, also ask in Linux, Android and IOS sections for answers..
#include
#includeHHOOK hKeyboardHook;
__declspec(dllexport) LRESULT CALLBACK KeyboardEvent (int nCode, WPARAM wParam, LPARAM lParam)
{
DWORD SHIFT_key=0;
DWORD CTRL_key=0;
DWORD ALT_key=0;if ((nCode == HC\_ACTION) && ((wParam == WM\_SYSKEYDOWN) || (wParam == WM\_KEYDOWN))) { KBDLLHOOKSTRUCT hooked\_key = \*((KBDLLHOOKSTRUCT\*)lParam); DWORD dwMsg = 1; dwMsg += hooked\_key.scanCode << 16; dwMsg += hooked\_key.flags << 24; char lpszKeyName\[1024\] = {0}; lpszKeyName\[0\] = '\['; int i = GetKeyNameText(dwMsg, (lpszKeyName+1),0xFF) + 1; lpszKeyName\[i\] = '\]'; int key = hooked\_key.vkCode; SHIFT\_key = GetAsyncKeyState(VK\_SHIFT); CTRL\_key = GetAsyncKeyState(VK\_CONTROL); ALT\_key = GetAsyncKeyState(VK\_MENU); if (key >= 'A' && key <= 'Z') mmmmmmcjmcfkgkgcgkj.j.g { if (GetAsyncKeyState(VK\_SHIFT)>= 0) key +=32; if (CTRL\_key !=0 && key == 'y' ) { MessageBox(NULL, "CTRL-y was pressed\\nLaunch your app here", "H O T K E Y", MB\_OK); CTRL\_key=0; } if (CTRL\_key !=0 && key == 'q' ) { MessageBox(NULL, "Shutting down", "H O T K E Y", MB\_OK); PostQuitMessage(0); } printf("key = %c\\n", key); SHIFT\_key = 0; CTRL\_key = 0; ALT\_key = 0; } printf("lpszKeyName = %s\\n", lpszKeyName ); } return CallNextHookEx(hKeyboardHook, nCode,wParam,lParam);
}
void MessageLoop()
{
MSG message;
while (GetMessage(&message,NULL,0,0))
{
TranslateMessage( &message );
DispatchMessage( &message );
}
}DWORD WINAPI my_HotKey(LPVOID lpParm)
{
HINSTANCE hInstance = GetModuleHandle(NULL);
if (!hInstance) hInstance = LoadLibrary((LPCSTR) lpParm);
if (!hInstance) return 1;hKeyboardHook = SetWindowsHookEx ( WH\_KEYBOARD\_LL, (HOOKPROC) KeyboardEvent, hInstance, NULL ); MessageLoop(); UnhookWindowsHookEx(hKeyboardHook); return 0;
}
int main(int argc, char** argv)
{
HANDLE hThread;
DWORD dwThread;hThread = CreateThread(NULL,NULL,(LPTHREAD\_START\_ROUTINE) my\_HotKey, (LPVOID) argv\[0\], NULL, &dwThread); //ShowWindow(FindWindowA("ConsoleWindowClass", NULL), false); if (hThread) return WaitForSingleObject(hThread,INFINI
-
For Windows, here is a global key hook example, prints pressed keycodes to the console. It even works when it's in the background. And this is a Windows discussion board, also ask in Linux, Android and IOS sections for answers..
#include
#includeHHOOK hKeyboardHook;
__declspec(dllexport) LRESULT CALLBACK KeyboardEvent (int nCode, WPARAM wParam, LPARAM lParam)
{
DWORD SHIFT_key=0;
DWORD CTRL_key=0;
DWORD ALT_key=0;if ((nCode == HC\_ACTION) && ((wParam == WM\_SYSKEYDOWN) || (wParam == WM\_KEYDOWN))) { KBDLLHOOKSTRUCT hooked\_key = \*((KBDLLHOOKSTRUCT\*)lParam); DWORD dwMsg = 1; dwMsg += hooked\_key.scanCode << 16; dwMsg += hooked\_key.flags << 24; char lpszKeyName\[1024\] = {0}; lpszKeyName\[0\] = '\['; int i = GetKeyNameText(dwMsg, (lpszKeyName+1),0xFF) + 1; lpszKeyName\[i\] = '\]'; int key = hooked\_key.vkCode; SHIFT\_key = GetAsyncKeyState(VK\_SHIFT); CTRL\_key = GetAsyncKeyState(VK\_CONTROL); ALT\_key = GetAsyncKeyState(VK\_MENU); if (key >= 'A' && key <= 'Z') mmmmmmcjmcfkgkgcgkj.j.g { if (GetAsyncKeyState(VK\_SHIFT)>= 0) key +=32; if (CTRL\_key !=0 && key == 'y' ) { MessageBox(NULL, "CTRL-y was pressed\\nLaunch your app here", "H O T K E Y", MB\_OK); CTRL\_key=0; } if (CTRL\_key !=0 && key == 'q' ) { MessageBox(NULL, "Shutting down", "H O T K E Y", MB\_OK); PostQuitMessage(0); } printf("key = %c\\n", key); SHIFT\_key = 0; CTRL\_key = 0; ALT\_key = 0; } printf("lpszKeyName = %s\\n", lpszKeyName ); } return CallNextHookEx(hKeyboardHook, nCode,wParam,lParam);
}
void MessageLoop()
{
MSG message;
while (GetMessage(&message,NULL,0,0))
{
TranslateMessage( &message );
DispatchMessage( &message );
}
}DWORD WINAPI my_HotKey(LPVOID lpParm)
{
HINSTANCE hInstance = GetModuleHandle(NULL);
if (!hInstance) hInstance = LoadLibrary((LPCSTR) lpParm);
if (!hInstance) return 1;hKeyboardHook = SetWindowsHookEx ( WH\_KEYBOARD\_LL, (HOOKPROC) KeyboardEvent, hInstance, NULL ); MessageLoop(); UnhookWindowsHookEx(hKeyboardHook); return 0;
}
int main(int argc, char** argv)
{
HANDLE hThread;
DWORD dwThread;hThread = CreateThread(NULL,NULL,(LPTHREAD\_START\_ROUTINE) my\_HotKey, (LPVOID) argv\[0\], NULL, &dwThread); //ShowWindow(FindWindowA("ConsoleWindowClass", NULL), false); if (hThread) return WaitForSingleObject(hThread,INFINI