Skip to content

Instantly share code, notes, and snippets.

@amrutnrp
Last active July 16, 2022 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amrutnrp/4f537eb5327a145a05d4ec2be81ccc31 to your computer and use it in GitHub Desktop.
Save amrutnrp/4f537eb5327a145a05d4ec2be81ccc31 to your computer and use it in GitHub Desktop.
Kay map to different language- 1->1 mapping
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include <iostream>
int LUT[2][8] = {
{
0,0,0,0, 0,0,0,0
},
{
1, 0x0B33,0,0,0,0,0,0
}
};
HHOOK hHook{ NULL };
int LUTindex;
enum Keys
{
ShiftKey = 16,
Capital = 20,
};
int shift_active() {
return GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0;
}
int capital_active() {
return (GetKeyState(VK_CAPITAL) & 1) == 1;
}
int ctrl_active() {
return GetKeyState(VK_LCONTROL) < 0 || GetKeyState(VK_RCONTROL) < 0;
}
int alt_active (){
return GetKeyState(VK_LMENU) < 0 || GetKeyState(VK_RMENU) < 0;
}
LRESULT CALLBACK keyboard_hook(const int nCode, const WPARAM wParam, const LPARAM lParam) {
if (wParam == WM_KEYDOWN) {
KBDLLHOOKSTRUCT *kbdStruct = (KBDLLHOOKSTRUCT*)lParam;
DWORD wVirtKey = kbdStruct->vkCode;
DWORD wScanCode = kbdStruct->scanCode;
BYTE lpKeyState[256];
GetKeyboardState(lpKeyState);
lpKeyState[Keys::ShiftKey] = 0;
lpKeyState[Keys::Capital] = 0;
if (shift_active()) {
lpKeyState[Keys::ShiftKey] = 0x80;
}
if (capital_active()) {
lpKeyState[Keys::Capital] = 0x01;
}
LUTindex =0;
if (!(ctrl_active() || alt_active() )){
if (wVirtKey == 0x41)
LUTindex = 1;
}
//index = 0;
//find the index of customised keys, if index =0, then don't process it
// if index is non-zero use it later to find addiitional information
if (LUTindex > 0){
std::cout << "LUT Key pressed" << std::endl;
INPUT inputs[LUT[LUTindex][0]] = {};
ZeroMemory(inputs, sizeof(inputs));
for (int s =0; s<LUT[LUTindex][0] ; s++)
{
inputs[s].type = INPUT_KEYBOARD;
inputs[s].ki.wVk = 0;
inputs[s].ki.wScan = LUT[LUTindex][s+1] ;
inputs[s].ki.dwFlags = KEYEVENTF_UNICODE;
std::cout<< s<< " "<< LUT[LUTindex][s+1]<<std::endl;
}
UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
if (uSent != ARRAYSIZE(inputs))
{
std::cout<<"SendInput failed: "<<std::endl;
}
// proessing done
return 1;
}
char result;
ToAscii(wVirtKey, wScanCode, lpKeyState, (LPWORD)&result, 0);
std::cout << result ;
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
int main(int argc, char* argv[])
{
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_hook, NULL, 0);
if (hHook == NULL) {
std::cout << "Keyboard hook failed!" << std::endl;
return 1;
}
while (GetMessage(NULL, NULL, 0, 0));
return 0;
}
@amrutnrp
Copy link
Author

this code maps key 'a' to unicode 'odia l'.
That way one can map each individual keys to a specific unicode character.
Although, it doesn't support phenotic type systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment