Question

I am working a on project that needs virtual input which is being coded in Microsoft Visual Studios using the windows.h header. To do this I am using the keybd_event() method and the VkKeyScan() method:

keybd_event(VkKeyScan('w'), 0, 0, 0);
keybd_event(VkKeyScan('w'), 0, KEYEVENTF_KEYUP, 0);

However, the virtual input is only being recognized by some programs, such as Notepad, Command Prompt, browsers, and other applications that use text fields. The purpose of virtual input for my project is to use a client to control "VisualGameBoyAdvance" which takes keyboard input that is then translated into a command such as 'w' = start, 'z' = a button, etc.

Why is the virtual input being read when using applications in text fields, but not as commands? Are there alternative methods of the windows.h header file or are there better methods in the header?

Update: I have been trying to use VkKeyScanEx() as an alternative method for taking virtual input as a shot-in-the-dark effort. How to I specify my input locale identifier? I have been trying to use UTF-8 and en_AU.UTF-8, with no luck. Is there a chart that translates how to specify this?

I've also tried using

keybd_event(GetKeyState('w'), 0, 0, 0);
keybd_event(GetKeyState('w'), 0, KEYEVENTF_KEYUP, 0);

Which did not work at all and tried

while(1){
        /*Sleep(1000);
        keybd_event(GetKeyState('w'), 0, 0, 0);
        keybd_event(GetKeyState('w'), 0, KEYEVENTF_KEYUP, 0);*/
        // Pause for 5 seconds.
    Sleep(500);

    // 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;

    // Press the "W" key
    ip.ki.wVk = 0x57; // virtual-key code for the "a" key
    ip.ki.dwFlags = 0; // 0 for key press
    SendInput(1, &ip, sizeof(INPUT));

    // Release the "A" key
    ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
    SendInput(1, &ip, sizeof(INPUT));

    // Exit normally
    }
Was it helpful?

Solution

The problem was that the game was running though DirectX, which prevented virtual keyboard strokes. By rending the game right from the sys, it avoided directx all together and worked fine :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top