gpt4 book ai didi

c++ - 当我想发送 "num8"时,SendInput 发送 "vk_up"?怎么会?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:37:50 25 4
gpt4 key购买 nike

好吧,我正在尝试对游戏进行简单的修改,这是模拟按键的代码:

#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;
}

问题在于,当我想发送向上箭头键时,会发送小键盘 8 键(可能是因为我的硬件键盘?)。当我按下键盘上的箭头键时,游戏中的飞机会前进......当我模拟向上箭头时,我的推进器会改变旋转(旋转变化映射到数字 8)。同样的情况分别发生在向下箭头 - num2、向左箭头 - num4 和向右箭头 - num6 上。

这是怎么回事?

__

可能不相关,但如果您想查看控制飞机的代码,就是这样:

(它在 PAWN - 一种脚本语言中)

        #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.." );
}

最佳答案

根据scancodes 2 page和它的主页,硬件默认扫描码集是 2,向上箭头的代码是 E0,75,对于 numpad8 只是普通的 75,这意味着箭头键是一个扩展键,所以你需要启用扩展键旗帜。此代码成功地使您能够操作脚本中的数据:

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));
}

脚本的示例用法:

        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.." );
}

允许您使用 5、6、7、8 键更改标志,并使用 9 和 0 更改输入键

关于c++ - 当我想发送 "num8"时,SendInput 发送 "vk_up"?怎么会?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14026496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com