Click here to Skip to main content
16,006,475 members
Home / Discussions / C#
   

C#

 
QuestionHow can I find out which key was pressed Pin
Mridang Agarwalla15-Aug-05 19:58
Mridang Agarwalla15-Aug-05 19:58 
AnswerRe: How can I find out which key was pressed Pin
Mridang Agarwalla15-Aug-05 20:09
Mridang Agarwalla15-Aug-05 20:09 
GeneralRe: How can I find out which key was pressed Pin
Christian Graus15-Aug-05 20:12
protectorChristian Graus15-Aug-05 20:12 
GeneralRe: How can I find out which key was pressed Pin
Mridang Agarwalla15-Aug-05 20:21
Mridang Agarwalla15-Aug-05 20:21 
AnswerRe: How can I find out which key was pressed Pin
Christian Graus15-Aug-05 20:10
protectorChristian Graus15-Aug-05 20:10 
GeneralRe: How can I find out which key was pressed Pin
Mridang Agarwalla15-Aug-05 23:07
Mridang Agarwalla15-Aug-05 23:07 
AnswerRe: How can I find out which key was pressed Pin
Hadi Fakhreddine15-Aug-05 20:39
Hadi Fakhreddine15-Aug-05 20:39 
AnswerRe: How can I find out which key was pressed Pin
snouto15-Aug-05 22:17
snouto15-Aug-05 22:17 
how are you my friend .
listen my friend about handling the keydown event is not useful and wasting time if you try to handle it through your keydown event handling cause you will need to nest alot alot of if statements and switch keywords and it is not practical you need something like keylogger code to log any keys pressed even if your form is activated or not then you can handle the specific key when it is pressed like the following code :-
<br />
/*you need first to interoperate dll found in the system itself so you need to call the namespace for handling this  */<br />
<br />
system.Runtime.InteroServices;<br />
/*<br />
Then you need to call the function of keys and override it<br />
*/<br />
[Dllimport("User32.dll")]<br />
Public static extern short GetAsyncKeyState(System.Windows.forms.Keys vkey);<br />
[Dllimport("User32.dll")]<br />
public static extern short GetAsyncKeyState(System.Int32 vkeys);<br />
/* now we called the User32.dll found in your system32 of your current windows Os and called the function that handling the keys pressed from the keyboard to get their values and iterate through system Asynchronously */<br />
//You need to initialize timer to Listen to keys pressing <br />
//As the following<br />
System.Timers.Timer mytimer;<br />
//and initialize new keybuffer to store the keyvalue in it<br />
System.String KeyBuffer;<br />
<br />
//Initialize the event handler model of the timer to listen<br />
//to the keypressing as the following<br />
Private void mytimer_Elapsed(object o , System.Timers.ElapsedEventargs args)<br />
{<br />
foreach(System.Int32 i in Enum.GetValues(typeof(Keys)))<br />
{<br />
if(GetAsyncKeyState(i) == -32767)<br />
{<br />
//here we store the key Value in the keybuffer string<br />
//we initialized At the begining.<br />
keybuffer += Enum.GetName(typeof(keys),i);<br />
TextBox.Text += KeyBuffer;<br />
Keybuffer = "";<br />
}<br />
}<br />
}<br />
//in the constructor add the delegate of this event <br />
public YourKeyLogger()<br />
{<br />
mytimer.Elapsed += new ElapsedEventHandler(this.mytimer_elapsed);<br />
}<br />


I hope the code can do the work for you
Thanks my friend

Miss With The Best And Die Like The Rest
GeneralDataGrid Pin
econner15-Aug-05 19:04
econner15-Aug-05 19:04 
GeneralRe: DataGrid Pin
Alomgir Miah16-Aug-05 3:54
Alomgir Miah16-Aug-05 3:54 
GeneralDesigner problem Pin
Kerby15-Aug-05 18:34
Kerby15-Aug-05 18:34 
GeneralDateTimePicker in Datagrid Pin
deep715-Aug-05 17:57
deep715-Aug-05 17:57 
GeneralRe: DateTimePicker in Datagrid Pin
Alomgir Miah16-Aug-05 3:43
Alomgir Miah16-Aug-05 3:43 
GeneralRe: DateTimePicker in Datagrid Pin
deep716-Aug-05 20:52
deep716-Aug-05 20:52 
GeneralRe: DateTimePicker in Datagrid Pin
Alomgir Miah17-Aug-05 5:39
Alomgir Miah17-Aug-05 5:39 
Generalstil having csc.exe problems Pin
Heinz_15-Aug-05 17:49
Heinz_15-Aug-05 17:49 
GeneralRe: stil having csc.exe problems Pin
Vasudevan Deepak Kumar15-Aug-05 18:55
Vasudevan Deepak Kumar15-Aug-05 18:55 
GeneralRe: stil having csc.exe problems Pin
Guffa15-Aug-05 18:57
Guffa15-Aug-05 18:57 
Generalruntime compile problem Pin
sduhd15-Aug-05 16:36
sduhd15-Aug-05 16:36 
QuestionDo timers run out ? Pin
Christian Graus15-Aug-05 15:38
protectorChristian Graus15-Aug-05 15:38 
AnswerRe: Do timers run out ? Pin
S. Senthil Kumar15-Aug-05 23:49
S. Senthil Kumar15-Aug-05 23:49 
GeneralRe: Do timers run out ? Pin
Christian Graus16-Aug-05 13:21
protectorChristian Graus16-Aug-05 13:21 
GeneralRe: Do timers run out ? Pin
Robert M Greene16-Aug-05 15:05
Robert M Greene16-Aug-05 15:05 
GeneralRe: Do timers run out ? Pin
Christian Graus16-Aug-05 15:18
protectorChristian Graus16-Aug-05 15:18 
GeneralRe: Do timers run out ? Pin
Robert M Greene16-Aug-05 15:25
Robert M Greene16-Aug-05 15:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.