Windows Develop Bookmark and Share   
 index > Windows Forms General > checking if a key is pressed
 

checking if a key is pressed

I know how to check if a key is pressed if I'm in a method. But lets say I just want to check if something is pressed at any point during the program. How do I go about doing that? What/Where do I add to let this happen?
HeyJP  Monday, July 16, 2007 7:43 PM
If you want an event any time a key is pressed, you could use a global key hook. See http://www.codeproject.com/csharp/globalhook.asp for an implementation.

Or do you want to be able to read the current keyboard state from a specific point in the code?
sirjis  Monday, July 16, 2007 7:46 PM
If you are using WinForms you can set the forms KeyPreview property to true, then the form fires Key events whenever a key is pressed. Hooking in with a global hook gives you all key presses regardless if they have anything to do with your app.
beshaghy  Monday, July 16, 2007 8:07 PM
If you want an event any time a key is pressed, you could use a global key hook. See http://www.codeproject.com/csharp/globalhook.asp for an implementation.

Or do you want to be able to read the current keyboard state from a specific point in the code?
sirjis  Monday, July 16, 2007 7:46 PM
If you are using WinForms you can set the forms KeyPreview property to true, then the form fires Key events whenever a key is pressed. Hooking in with a global hook gives you all key presses regardless if they have anything to do with your app.
beshaghy  Monday, July 16, 2007 8:07 PM

You can use google to search for other answers

Custom Search

More Threads

• DataAdapter Update Problem[Argent]
• Where should I put code to gradient fill a form?
• change the form title bar icons
• How do I display the column and line number using TextBox?
• how to make buttons useable when the thread is suspended (C#)
• "Don't show again" MessageBox
• ComboBox Sorting Bug
• How do i pass control to another form in a button click event
• list view(or)Tree view+C#
• Slow UI updates when enabling/disable multiple controls at once