I’ve got a C# console application with some pieces of text that represent buttons so for example it looks like this [ D ][ E ][ F ][ G ]
When the user presses the button I want the button to be highlighted which is no problem as what im currently doing is rewriting over the button with Console.BackgroundColor set.
What I want to do is that they key be constantly highlighted while the key is held down but as soon as the key is lifted again the highlighting to be removed, if possible i’d also like multiple keys to be pressed at the same time. This is what I can’t figure out how to do?
Hope that makes sense 🙂
Any help?
Thanks
If you are willing to add a reference to Windows.Forms, call Application.Run() to run a message queue, and call external Windows DLLs, you can do it using this code: http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx
That page will show you how to hook the low-level key-down keyboard event.
To also hook key-up keyboard events, you’ll need to add a WM_KEYUP constant:
And then modify the
HookCallbackmethod:That will give you “Up” and “Down” messages for every key press. From there you should be able to incorporate it into your app.
Good luck!