The problem, however, is that after two of those shortcuts, it won't do anything else, and the shift key state remains down, until I manually press and release the physical shift key.
I have tried both methods, using SendInput () and using keybd_event ().
SendInput () method:
#include <windows.h>
#include <stdlib.h>
int WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, int CmdShow){
MSG msg;
struct INPUT input_data;
int i;
int state= 0;
memset (&input_data, 0, sizeof (input_data));
RegisterHotKey (0, 1, MOD_CONTROL, 0x37);
while (GetMessage (&msg, 0, 0, 0)){
if (msg.message == WM_HOTKEY){
if (msg.wParam == 1){
input_data.type= INPUT_KEYBOARD;
input_data.ki.wVk= VK_SHIFT;
input_data.ki.dwExtraInfo= GetMessageExtraInfo ();
if (state) input_data.ki.dwFlags= KEYEVENTF_KEYUP;
else input_data.ki.dwFlags= 0;
SendInput (1, &input_data, sizeof (INPUT));
state= state * -1 + 1;
}
} else if (msg.message == WM_CLOSE){
ReplyMessage (0);
break;
} else {
}
ReplyMessage (0);
}
UnregisterHotKey (0, 1);
ExitProcess (0);
}
keybd_event () method:
#include <windows.h>
#include <stdlib.h>
int WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, int CmdShow){
MSG msg;
int state= 0;
RegisterHotKey (0, 1, MOD_CONTROL, 0x37);
while (GetMessage (&msg, 0, 0, 0)){
if (msg.message == WM_HOTKEY){
if (msg.wParam == 1){
keybd_event (VK_SHIFT, 0, KEYEVENTF_KEYUP * state, GetMessageExtraInfo ());
state= state * -1 + 1;
}
} else if (msg.message == WM_CLOSE){
ReplyMessage (0);
break;
} else {
}
ReplyMessage (0);
}
UnregisterHotKey (0, 1);
ExitProcess (0);
return 0;
}
What is wrong with it? What's causing the unresponsiveness?
Thanks in advance.
RR


Sign In
Create Account


Back to top









