好吧,我正在尝试对游戏进行简单的修改,这是模拟按键的代码:
#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;
}
问题在于,当我想发送向上箭头键时,发送了 numpad8 键(可能是因为我的硬件键盘?)。当我按下键盘上的箭头键时,游戏中的飞机会前进。当我模拟向上箭头时,我的推进器会改变旋转(旋转变化映射到数字 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.." );
}