c++ - SendMessage WM_KEYDOWN doesn't always work -


i'm trying make program sending keypresses window of game. bot if like. i'm using sendmessage/postmessage wm_keydown , wm_keyup proper lparam window. other method i've tried use sendinput. , send/post setkeyboardstate.

the problem methods work same way - not always. mean i'm trying send vk_f9 window every 10 seconds using timer. can work 3 times, or 5 times, or 0 times. means after random sends or posts stops working. if press f9 on keyboard next send works!

what can problem there? may there state i'm not aware of?

thanks in advance!

in c++ i've tried one:

void generatekey(int vk, bool bextended) {  keybdinput  kb = {0}; input       input = {0};  /* generate "key down" */ if (bextended) { kb.dwflags  = keyeventf_extendedkey; } kb.wvk  = vk; input.type  = input_keyboard; input.ki  = kb; sendinput(1, &input, sizeof(input)); sleep(300);  /* generate "key up" */ zeromemory(&kb, sizeof(keybdinput)); zeromemory(&input, sizeof(input)); kb.dwflags  =  keyeventf_keyup; if (bextended) { kb.dwflags |= keyeventf_extendedkey; } kb.wvk = vk; input.type = input_keyboard; input.ki = kb; sendinput(1, &input, sizeof(input));  return; } 

in delphi used this:

procedure fkey(win:thandle; key:integer; special: boolean); var lparam: longint; begin  lparam := makelong(0, mapvirtualkey(key, 0));  if (special)     lparam:=lparam or $1000000;  sendmessage(win,wm_keydown,key,lparam);  sendmessage(win,wm_keyup,key,$c0000000); end; 

p.s.: may clue - logitech x7 mouse macros works fine.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -