First step: Change the property "KeyPreview" to true in the form where you want to implement the shortcut key;
The second step: in the form to implement the shortcut key in the onkeypress event to fill in a process name (in Object inspector), fill in and enter into the event code to fill in the section;
Step three: Fill in the event handling process, here is an example:
Procedure tfrmmain.keypress (Sender:tobject; var key:char);
Begin
If key in ["] Then
Begin
B_play_pause.click;
End
End
The above example realizes "in an active form, pressing the SPACEBAR is equivalent to clicking the Play/Pause button", which is also a shortcut for many of the current players. Inside the brackets can be filled with multiple characters, in the middle with a comma separated by the English half-width, to monitor the function of multiple shortcut keys, in addition, the brackets also support the sub-boundary type, for example: [' 0 ' ... ' 9 ', ' a ' ... ' z '] This enables input monitoring of the digital 0~9, lowercase English letters a~z The If post-processing process can perform a case key of operation on key, for example:
Case Key of
0:to do something one;
1:to do something;
When the keyboard input 0 o'clock executes the to-do something one statement, when the keyboard input 1 o'clock executes the to-do something, the equivalent of the switch statement in the C language.
http://blog.csdn.net/chaijunkun/article/details/4125624
Define shortcut keys in Delphi without registering hotkeys (simple and ingenious, but the current form is active)