LRESULT CALLBACK ProcessMsgs(HWND hwnd, UINT msg, WPARAM param, LPARAM lparam) {
switch (msg) {
case WM_HOTKEY: {
WORD AUXKEY = LOWORD(lparam);
WORD MKEY = HIWORD(lparam);
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.dwFlags = KEYEVENTF_UNICODE;
ip.ki.wVk = 0; // 0 because of unicode
if (AUXKEY == MOD_ALT) {
switch (MKEY) { // Lowercase
case 0x41: // A
ip.ki.wScan = 0xE1; // lowercase a with accent
break;
case 0x4E: // N
ip.ki.wScan = 0xF1; // lowercase n with tilde accent
break;
case 0x4F: // O
ip.ki.wScan = 0xF3; // lowercase o with accent
break;
case 0x55: // U
ip.ki.wScan = 0xFA; // lowercase u with accent
break;
case 0x49: // I
ip.ki.wScan = 0xED; // lowercase i with accent
break;
case 0xBD: // DASH
ip.ki.wScan = 0x2014; // em dash
break;
}
SendInput(1, &ip, sizeof(INPUT)); // breakpoint here
}
if (AUXKEY == MOD_ALT + MOD_SHIFT) {
switch (MKEY) { // Uppercase
case 0x41: // A
ip.ki.wScan = 0xC1; // uppercase a with accent
break;
case 0x4E: // N
ip.ki.wScan = 0xF1; // uppercase n with tilde accent
break;
case 0x4F: // O
ip.ki.wScan = 0xD2; // uppercase o with accent
break;
case 0x55: // U
ip.ki.wScan = 0xDA; // uppercase u with accent
break;
case 0x49: // I
ip.ki.wScan = 0xCD; // uppercase i with accent
break;
}
SendInput(1, &ip, sizeof(INPUT));
}
ip.ki.dwFlags = KEYEVENTF_KEYUP + KEYEVENTF_UNICODE; // KEYEVENTF_KEYUP for key release
SendInput(1, &ip, sizeof(INPUT));
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, msg, param, lparam);
}
}
This code types a vowel with an accent on it when combined with the ALT key. It recieves the message WM_HOTKEY from registered hotkeys like this:
RegisterHotKey(
TheWindow,
NULL,
MOD_ALT,
0x41 // A
);
There are hotkeys for all vowels, the letter N, and the dash character. The problem i'm having is the fact that the code works fine when I use a breakpoint on the line of the initial SendInput, but when I run it normally, no letter with accent is typed. All those breaks are there because the switch would always use the last case, I have no idea why.
The thing is when I run this very alpha and primitive version of the code I developed prior to the aforementioned code, it works fine without needing breakpoints (this version used CTRL as the indicator, I changed it to ALT because there are so many functions of programs that use CTRL plus a letter for user functions... the RegisterHotKey function uses MOD_CONTROL instead of MOD_ALT accordingly):
switch (msg) {
case WM_HOTKEY:
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0xE1; // lowercase a with accent
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.dwFlags = KEYEVENTF_UNICODE;
ip.ki.wVk = 0; // 0 because of unicode
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP | KEYEVENTF_UNICODE; // KEYEVENTF_KEYUP for key release
SendInput(1, &ip, sizeof(INPUT));
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, msg, param, lparam);
}
I know that I can use identifiers to simplify some of this, but regardless... that code functions, just with breakpoints... So odd.