Results 1 to 6 of 6

Thread: Simulating keypresses with alt/ctrl modifiers?

  1. #1

    Question Simulating keypresses with alt/ctrl modifiers?

    This is the closest thing to a 3rd party developers forum, so I'll have to ask it here even though it's not directly API related.

    I am trying to simulate an "Open Galaxy Map" keycombo to send to Elite Dangerous to make it open the map.

    I successfully have this working for various other ship functions. However, if the keycombo involves a modifier key like LeftAlt or LeftCtrl (like what I have bound for the galaxy map, LeftAlt+G) I cannot get Elite Dangerous to recognize the keypress.

    I am sending a proper sequence of keys with SendInput: KeyDown(LeftAlt), KeyDown(G), Wait(100ms), KeyUp(G), KeyUp(LeftAlt).

    I am sending these SendInput calls with the virtual key code for Alt (VK_MENU) as well as the correct scan code for LeftAlt (I know that ED only pays attention to the scan codes and ignores the higher level virtual key codes).

    But when I actually execute these calls, Elite Dangerous will recognize the G keypress but will not recognize the Ctrl or Alt modifier.

    Anyone successfully used SendInput to send keycombos to Elite Dangerous with Ctrl or Alt?

  2. #2
    I tried the exact same sequence (as well as a few others) and it seemed to work fine.

  3. #3
    How did you send it?

    Sending a LeftAlt+G to ED doesn't seem to work using SendInput, whether I send it as essentially SendInput([KeyDown(LeftAlt)]), SendInput([KeyDown(G)]), SendInput([KeyUp(G)]), SendInput([KeyUp(LeftAlt)]). Or as SendInput([KeyDown(LeftAlt), KeyDown(G), KeyUp(G), KeyUp(LeftAlt)]).

  4. #4
    My code is a little messy, but here are the relevant bits:

    This is the sequence I have defined in my client application:
    <Action type="key" key="G" state="true"/>
    <Action type="key" key="LeftAlt" state="true"/>
    <Action type="delay" delay="100"/>
    <Action type="key" key="LeftAlt" state="false"/>
    <Action type="key" key="G" state="false"/>
    It also worked when I swapped G and LeftAlt around.

    I never tried sending the entire sequence in a single SendInput call.

  5. #5
    Ok I did a bit of experimentation. Apparently while ED requires the scancode and seems to ignore the virtual code for normal keys (e.g. it ignores VK_W and needs the W scancode instead), for modifier keys ED actually does use the virtual code and ignores the scancode. Specifically, it ignores the "left ctrl" scan code, doesn't listen for the CTRL virtual code (the one you're supposed to send), and instead expects you to send the LCTRL virtual code... the code that documentations states "Used only as parameters to [...] GetKeyState()" and are not meant to be used with SendInput.

    So I now have LeftShift, LeftControl, RightAlt, RightShift, RightControl working.

    Unfortunately I can't seem to get LeftAlt to work. Using RMENU works to get RightAlt working. But neither LMENU or MENU work for getting LeftAlt to work.

    Since I now have the other modifier keys working I am guessing there may be some OS interception going on for (Left)Alt+ key combos.

  6. #6
    Ok the LeftAlt issue was just a bug in InputSimulatorPlus. The LMENU key is not supposed to be sent with the ExtendedKey flag but was being sent with it.