5

さて、私はゲーム用に簡単な変更を加えようとしています。これは、キーの押下をエミュレートするコードです。

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

2 に答える 2

7

scancodes 2 ページとそのメイン ページによると、ハードウェアのデフォルトのスキャンコード セットは 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 で入力キーを変更できます。

于 2012-12-25T14:10:34.953 に答える