Answered by:
Handling Key Event in Console Application

Question
-
Hi all
i want to handle the event when user press a key (suppose he press Tab key)
now in my console application i want to do something like
if (key == Keys.Tab)
{
//some logic
e. handled = true;
}
so that no input goes to an active application from tab key
I can easily do this in windows but not able to do in console application
any help would be great
Tuesday, January 24, 2012 9:49 AM
Answers
-
I suggest to you the following links:
http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx
http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C
http://stackoverflow.com/questions/4598895/how-to-create-non-window-bound-keyboard-shortcuts
http://www.geekpedia.com/tutorial53_Getting-input-from-keyboard.html
- Proposed as answer by Leo Liu - MSFTModerator Thursday, January 26, 2012 11:26 AM
- Marked as answer by Leo Liu - MSFTModerator Wednesday, February 1, 2012 4:46 AM
Tuesday, January 24, 2012 12:03 PM
All replies
-
Hi, you need to handle the keys in this way:
ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.Tab) { //do something... }
- Proposed as answer by turibbioMVP Tuesday, January 24, 2012 11:12 AM
- Edited by turibbioMVP Tuesday, January 24, 2012 11:13 AM
Tuesday, January 24, 2012 11:11 AM -
i do not want to send Enter key as input to the active window
by employing your logic //do something... is performed
then Enter key functionality is performed
for eg.
i want that on pressing F font size of notepad should change
Now By employing this logic when i press f font gets changed along with f written on notepad.
Tuesday, January 24, 2012 11:23 AM -
I'm sorry, let me see if I understand correctly what you're trying to do:
You want "something" that catch all user input, like a background process, which take the pressed key, do some work, and then send nothing to active window?
Tuesday, January 24, 2012 11:40 AM -
yes something like thatTuesday, January 24, 2012 11:41 AM
-
I suggest to you the following links:
http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx
http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C
http://stackoverflow.com/questions/4598895/how-to-create-non-window-bound-keyboard-shortcuts
http://www.geekpedia.com/tutorial53_Getting-input-from-keyboard.html
- Proposed as answer by Leo Liu - MSFTModerator Thursday, January 26, 2012 11:26 AM
- Marked as answer by Leo Liu - MSFTModerator Wednesday, February 1, 2012 4:46 AM
Tuesday, January 24, 2012 12:03 PM