code_junkie

Capturing key press messages

Nov 11th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  2. {
  3. const int WM_KEYDOWN = 0x100;
  4. const int WM_SYSKEYDOWN = 0x104;
  5.  
  6. if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
  7. {
  8. switch (keyData)
  9. {
  10. case Keys.Down:
  11. this.Text = "Down Arrow Captured";
  12. break;
  13.  
  14. case Keys.Up:
  15. this.Text = "Up Arrow Captured";
  16. break;
  17.  
  18. case Keys.Tab:
  19. this.Text = "Tab Key Captured";
  20. break;
  21.  
  22. case Keys.Control | Keys.M:
  23. this.Text = "<CTRL> + M Captured";
  24. break;
  25.  
  26. case Keys.Alt | Keys.Z:
  27. this.Text = "<ALT> + Z Captured";
  28. break;
  29. }
  30. }
  31.  
  32. return base.ProcessCmdKey(ref msg, keyData);
  33. }
Add Comment
Please, Sign In to add comment