0

I am using Windows 7 Ultimate 64-bit. This is a function I stumbled across online and used before with no issues but now I am having a problem. Regardless of what character I send to it, it will just send a forward slash keystroke /. Here is the function:

void GenerateKey(int vk, BOOL bExtended)
{

    KEYBDINPUT  kb = {0};
    INPUT       Input = {0};

    /* Generate a "key down" */
    if (bExtended) { kb.dwFlags  = KEYEVENTF_EXTENDEDKEY; }
    kb.wVk  = vk;
    Input.type  = INPUT_KEYBOARD;
    Input.ki  = kb;
    SendInput(1, &Input, sizeof(Input));

    /* Generate a "key up" */
    ZeroMemory(&kb, sizeof(KEYBDINPUT));
    ZeroMemory(&Input, sizeof(INPUT));
    kb.dwFlags  =  KEYEVENTF_KEYUP;
    if (bExtended) { kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; }
    kb.wVk = vk;
    Input.type = INPUT_KEYBOARD;
    Input.ki = kb;
    SendInput(1, &Input, sizeof(Input));

    return;
}

Here's how I am calling it: GenerateKey('x', FALSE);

However, instead of an x I get a /. Can anyone see what's going wrong? I am using Visual Studio 2008.

rsjaffe
  • 5,600
  • 7
  • 27
  • 39
John
  • 31
  • 2
  • 3
    is this where you got it from: http://stackoverflow.com/questions/4427634/need-help-to-generate-keystrokes-into-existing-application-in-linux-environment-u ? –  Mar 05 '11 at 06:24
  • It's been floating around the internet for awhile now. I found my copy at cpluscplus.com's forums. – John Mar 05 '11 at 06:32
  • Using lower case 'x' is definitely wrong, that generates a F9 function key press (virtual key 0x78). Doesn't explain getting a '/' though. – Hans Passant Mar 05 '11 at 08:13

1 Answers1

1

KEYBDINPUT.wVk is a virtual key code, not an ascii char.

http://msdn.microsoft.com/en-us/library/ms646271(v=vs.85).aspx

my fat llama
  • 171
  • 3