0

I have a C# application which sends keyboard and mouse events to a game. In the game there's a small UI portion which can change based on what we want to see (like GPS map, different actions to take etc). Sometimes in this portion of the UI we have to press 'Enter' (or another key depending on how the user configured the game's keys) to activate something (for example, press Enter to activate Rescue service).

Now , the problem: all the key events sent from the c# app are processed fine OUTSIDE of this UI, except this 'activate' thing. At first I thought there's a problem with the 'ENTER' (Return) key event, but after chaning it to another key that was working in-game, I noticed that key is also ignored.

I am not sure if it's a problem related to the way I send the messages (maybe it needs to have a specific parameter) and it can be fixed by modifying my app, or is some blockage in-game - and in this case there's nothing I can do.

Here's the code I use to send the key events:

public static void PressKey(short key)
        {
            INPUT[] inputs = new INPUT[]
            {
                new INPUT
                {
                    type = INPUT_KEYBOARD,
                    u = new InputUnion
                    {
                        ki = new KEYBDINPUT
                        {
                            wVk = (ushort)0,
                            wScan = (ushort)key,
                            dwFlags = KEYEVENTF_SCANCODE,
                            dwExtraInfo = IntPtr.Zero,
                        }
                    }
                },
                new INPUT
                {
                    type = INPUT_KEYBOARD,
                    u = new InputUnion
                    {
                        ki = new KEYBDINPUT
                        {
                            wVk = (ushort)0,
                            wScan = (ushort)key,
                            dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP,
                            dwExtraInfo = GetMessageExtraInfo(),
                        }
                    }
                }
            };
            SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
        }

But hoping its the 1st case, I would appreciate any help with this.

Added a screenshot in order to try to better explain the issue

  • (A) -> That is the UI window that requires "ENTER" to be pressed. Let's suppose that I modify the settings of the game to have "E" instead of "Enter" for the ACTIVATE action. Then the text "Call Assistance Service (ENTER)" will now show "Call Assistance Service (E)". By default, the "E" key is engine start in the game. And it works just fine (in the case (B)) . As soon as I change E to be 'Activate' , it's being completely ignored.
  • Another point which might (or might not) be relevant , is that the F-keys that can be at the bottom of the UI Window, also WORK just fine. I hope this clears up the things a little bit more.
Kara
  • 6,115
  • 16
  • 50
  • 57
eemerge
  • 75
  • 2
  • 9
  • I'm not sure we have enough information to solve the problem? Have you been able to reproduce the issue with step debugging? – Alyssa Haroldsen Aug 06 '15 at 22:52
  • I have not used step debugging since, from my point of view, the event DOES get sent - to give another example, if I switch between the game and a text-editing application like Notepad++ , all works fine there. What other kind of information (except step debugging) would you find useful? – eemerge Aug 06 '15 at 23:10

1 Answers1

0

I have found what the issue was, and I'm pretty sure it's related to how the game handles the input (but since it's not me who coded the game I cannot guarantee it).

Anyway, to fix my issue, a delay needs to be added between the KEYDOWN and KEYUP events. For the time being I'm using a Timer with a callback for that, but probably there are other ways to do it also (better or not).

Hope this will help someone someday :)

eemerge
  • 75
  • 2
  • 9