Prlnman

I am writing a program that captures input from a joystick/gamepad and maps the joy buttons to keyboard input. I already can capture the gamepad's input but I can't get the sending of keyboard input to work. I have tried using SendKeys.Send() but it isnt working for my purposes. I also tried using the SendMessage() function with WM_KEYDOWN and WM_KEYUP, but I'm not sure whether the window I'm sending messages to is correct, and I also dont know the numerical codes for the keyboard letters.

I have found a C# enum with all of the different messages that can be sent, but I would like a list of the codes for each key on the keyboard. Or if anyone has a better/more reliable way of simulating keyboard and mouse input it would be great.

Thanks in advance!


Re: Visual C# General Emulating keyboard presses and mouse events.

decyclone


Hi,

This article is not the same you might be looking for, but go through it. It might help you some other way.





Re: Visual C# General Emulating keyboard presses and mouse events.

sh_omer

Hi ,

There is an excellent article on how to simulate keys and mouse events on MSDN

http://msdn2.microsoft.com/en-us/library/ms171548.aspx
If you still find it confusing do let me know ..

Regards,
Omer


Please mark the post as answer if it helps you.





Re: Visual C# General Emulating keyboard presses and mouse events.

Prlnman

It is a very good article and works quite well. But the SendKeys.Send method will not work for me in all cases. It has worked for me when I try to send keys to another window, or form, but when I try to send keys to a game for instance the input is completely lost, or the game crashes.





Re: Visual C# General Emulating keyboard presses and mouse events.

dnilsson

I have the same issue, sending keys to a game does not work that good, if you ingame pull up a menu/console or something the input arrives but let's say you wanna send the key a for turnng left or key d for turning right... the input is lost. I fooled around with the Sendkeys application linked to in previous post and it worked once. I was able to send the keystroke F5 which takes a screenshot ingame, tried restarting the game, application, windows but I was never again able to accomplish this.