SendInput sends "num8" when I want to send "vk_up"? How so?

Well, I'm trying to make a simple modification for the game, and this is the code that emulates a keystroke:

#define PWNFUNC(a) static cell AMX_NATIVE_CALL a(AMX *amx, cell *params) PWNFUNC(EmulateKeyPressINPUT) { // This structure will be used to create the keyboard // input event. INPUT ip; // Set up a generic keyboard event. ip.type = INPUT_KEYBOARD; ip.ki.wScan = 0; // hardware scan code for key ip.ki.time = 0; ip.ki.dwExtraInfo = 0; ip.ki.wVk = params[2]; // virtual-key code for the "a" key switch(params[1]) { case WM_KEYDOWN: ip.ki.dwFlags = 0; // 0 for key press break; case WM_KEYUP: ip.ki.dwFlags = KEYEVENTF_KEYUP; break; } SendInput(1, &ip, sizeof(INPUT)); return 1; } 

the problem is that sometime, when I want to send the up arrow, the numpad8 key is sent (maybe because of my hardware keyboard?). When I press the arrow key on my keychain, the plane in the game goes forward ... and when I emulate the up arrow, my thrusters change rotation (the rotation change is displayed by the number 8). the same thing happens with the down arrow - num2, the left arrow - num4 and the right arrow - num6.

What's happening?

__

may be unrelated, but if you want to see the code that controls the plane, this is it:

(this is in PAWN - scripting language)

  #define KEYPRESS_DOWN 0x0100 #define KEYPRESS_UP 0x0101 GetMovementSpeed(pos[0][0],pos[0][1],pos[0][2],true); new Float:speed = floatsqroot(pos[0][0]*pos[0][0]+pos[0][1]*pos[0][1]+pos[0][2]*pos[0][2])*174.0; if ( speed > 260.0 ) speed = 260.0; if(GetVehicleModel() == 520)//f-22 airplane { static sent = 0; if(IsKeyDown(VK_TAB)) { if(speed < 200.0) { EmulateKeyPress(KEYPRESS_UP,VK_DOWN); EmulateKeyPress(KEYPRESS_DOWN,VK_UP); sent = 1; DrawText( id,50.0,160.0,0xFFFFFFFF, "GO birdy!! gooo!!!!" ); } else if(speed > 210.0) { EmulateKeyPress(KEYPRESS_UP,VK_UP); EmulateKeyPress(KEYPRESS_DOWN,VK_DOWN); sent = 2; DrawText( id,50.0,160.0,0xFFFFFFFF, "TOO fastststs!!!! SOTTP STOP!!!" ); } } else if(sent == 1) { EmulateKeyPress(KEYPRESS_UP,VK_UP); sent = 0; DrawText( id,50.0,160.0,0xFFFFFFFF, "You won't see this message" ); } else if(sent == 2) { EmulateKeyPress(KEYPRESS_UP,VK_DOWN); sent = 0; DrawText( id,50.0,160.0,0xFFFFFFFF, "Nor this one, c'mon if you do, you can notice a change in one f**king frame between 2 other frames?!" ); } else { DrawText( id,50.0,160.0,0xFFFFFFFF, "Something other is going on.. our relation ship is too complicated :(" ); } } else { DrawText( id,50.0,160.0,0xFFFFFFFF, "Well, f**k you too, no autopilot if you're not in an F-22.." ); } 
+4
source share
2 answers

According to scancodes 2 page and its main page, the scancode hardware set is 2, and the code for the up arrow is E0, 75, and for numpad8 it is just 75, which means that the arrow key is an extended key, so you need to enable extended key flag. This code successfully allows you to manage data from a script:

 PWNFUNC(EmulateKeyPressINPUT) { // This structure will be used to create the keyboard // input event. INPUT ip; // Set up a generic keyboard event. ip.type = INPUT_KEYBOARD; ip.ki.dwFlags = 0; if(params[4] == 1) { ip.ki.wScan = params[2]; // hardware scan code for key ip.ki.wVk = 0; // virtual-key code for the key ip.ki.dwFlags |= KEYEVENTF_SCANCODE; } else { ip.ki.wScan = 0; // hardware scan code for key ip.ki.wVk = params[2]; // virtual-key code for the key } ip.ki.time = 0; ip.ki.dwExtraInfo = 0; if(params[3] == 1) { ip.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; } if(params[1] == 1) { ip.ki.dwFlags |= KEYEVENTF_KEYUP; } return SendInput(1, &ip, sizeof(INPUT)); } 

usage example for script:

  GetMovementSpeed(pos[0][0],pos[0][1],pos[0][2],true); new Float:speed = floatsqroot(pos[0][0]*pos[0][0]+pos[0][1]*pos[0][1]+pos[0][2]*pos[0][2])*174.0; if ( speed > 260.0 ) speed = 260.0; if(GetVehicleModel() == 520)//f-22 airplane { static sent = 0; static status = 0; static vKEY_UP = VK_UP; static vKEY_DOWN = VK_DOWN; static bool:extended = false; static bool:hardware = false; if(IsKeyDown(VK_KEY_0)) { vKEY_UP = VK_NUMPAD8; vKEY_DOWN = VK_NUMPAD2; } else if(IsKeyDown(VK_KEY_9)) { vKEY_UP = VK_UP; vKEY_DOWN = VK_DOWN; } else if(IsKeyDown(VK_KEY_8)) { extended = true; } else if(IsKeyDown(VK_KEY_7)) { extended = false; } else if(IsKeyDown(VK_KEY_6)) { hardware = true; } else if(IsKeyDown(VK_KEY_5)) { hardware = false; } DrawText( id,50.0,170.0,0xFFFFFFFF, sprintf("UP: %x DOWN: %x Extended: %d Hardware: %d",vKEY_UP,vKEY_DOWN,extended,hardware) ); if(IsKeyDown(VK_TAB)) { if(speed < 200.0) { if(status == 0) { new PressedKeys[2]; PressedKeys[0] = EmulateKeyPress(KEYPRESS_UP,vKEY_DOWN,extended,hardware); PressedKeys[1] = EmulateKeyPress(KEYPRESS_DOWN,vKEY_UP,extended,hardware); DrawTextTimed(id,50.0,210.0,0xFFFFFFFF,sprintf("Presses:{%d,%d} if(speed < 200.0)",PressedKeys[0],PressedKeys[1]),2000,250,0); sent = 1; status = 1; } DrawText( id,50.0,160.0,0xFFFFFFFF, "GO birdy!! gooo!!!!" ); } else if(speed > 210.0) { if(status == 0) { new PressedKeys[2]; PressedKeys[0] = EmulateKeyPress(KEYPRESS_UP,vKEY_UP,extended,hardware); PressedKeys[1] = EmulateKeyPress(KEYPRESS_DOWN,vKEY_DOWN,extended,hardware); DrawTextTimed(id,50.0,210.0,0xFFFFFFFF,sprintf("Presses:{%d,%d} if(speed > 210.0)",PressedKeys[0],PressedKeys[1]),2000,250,1); sent = 2; status = 1; } DrawText( id,50.0,160.0,0xFFFFFFFF, "TOO fastststs!!!! SOTTP STOP!!!" ); } else { status = 0; EmulateKeyPress(KEYPRESS_UP,vKEY_UP,extended,hardware); EmulateKeyPress(KEYPRESS_UP,vKEY_DOWN,extended,hardware); } } else if(sent == 1) { DrawTextTimed(id,50.0,220.0,0xFFFFFFFF,sprintf("Presses:{%d} if(sent == 1)",EmulateKeyPress(KEYPRESS_UP,vKEY_UP,extended,hardware)),2000,250,2); sent = 0; status = 0; DrawText( id,50.0,160.0,0xFFFFFFFF, "You won't see this message" ); } else if(sent == 2) { DrawTextTimed(id,50.0,230.0,0xFFFFFFFF,sprintf("Presses:{%d} if(sent == 1)",EmulateKeyPress(KEYPRESS_UP,vKEY_DOWN,extended,hardware)),2000,250,3); sent = 0; status = 0; DrawText( id,50.0,160.0,0xFFFFFFFF, "Nor this one, c'mon if you do, you can notice a change in one frame between 2 other frames?!" ); } else { DrawText( id,50.0,160.0,0xFFFFFFFF, "Something other is going on.. our relation ship is too complicated :(" ); } } else { DrawText( id,50.0,160.0,0xFFFFFFFF, "Well, no autopilot if you're not in an F-22.." ); } 

allows you to change flags using 5,6,7,8 keys and enter keys with 9 and 0

+5
source

Just add the optional KEYEVENTF_EXTENDEDKEY flag:

 input.ki.dwflags |= KEYEVENTF_EXTENDEDKEY; 
+1
source

All Articles