SendInput发送"num8"消息.当我想发送"vk_up"时?怎么来的? [英] SendInput sends "num8" when I want to send "vk_up" ? How come?

查看:63
本文介绍了SendInput发送"num8"消息.当我想发送"vk_up"时?怎么来的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

#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也会发生同样的情况.

the problem with this is that somehow when I want to send an arrow up key the numpad8 key is sent (maybe it's because of my hardware keyboard?). When I press the arrow key on my keyboar the aircraft in the game goes forward.. and when I emulate the up arrow, then my thrusters change rotation (rotation change is mapped to num 8). the same happens with respectively arrow down - num2, left arrow - num4 and right arrow - num6.

这是怎么回事?

__

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

maybe unrelated but if you want to see the code which controls the aircraft, this is it:

(使用PAWN-一种脚本语言)

(it's in PAWN - a 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.." );
        }

推荐答案

根据扫描代码2页及其主页,硬件默认扫描代码集为2,向上箭头的代码为E0,75,而numpad8仅普通的75,这意味着箭头键是扩展键,因此您需要启用扩展键标志.此代码使您能够成功地处理脚本中的数据:

According to the scancodes 2 page and the main page of it, the hardware default scancode set is 2 and the code for arrow up is E0,75 and for numpad8 just plain 75, that means that the arrow key is an extended key, so you need to enable the extended key flag. This code succesfully enables you to manipulate the data from the 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));
}

该脚本的用法示例:

        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更改输入键

allows you to change the flags with 5,6,7,8 keys and the input keys with 9 and 0

这篇关于SendInput发送"num8"消息.当我想发送"vk_up"时?怎么来的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆