2010. február 1., hétfő

How to trap your own hot keys


Problem/Question/Abstract:

How to trap your own hot keys

Answer:

Windows has many default hot keys that your interface takes advantage of. However, you sometimes need to add your own hot keys to your form. How do you trap the hot keys when the user enters them?

To solve this problem, first set your form KeyPreview property to True. Next, add this line of code to your form's OnKeyDown event handler:


if (ssCtrl in Shift) and (chr(Key) in ['A', 'a']) then
  ShowMessage('Ctrl-A');


The OnKeyDown event will trap the keystrokes and perform the specified code in response.

Nincsenek megjegyzések:

Megjegyzés küldése