From Clomosy Docs

Revision as of 14:48, 23 December 2024 by ClomosyAdmin (talk | contribs)

In Clomosy, clSenderKeyChar contains a value representing the component that triggered the keyboard event when the event is processed (typically, a keyboard event is tied to a form or a button). This value contains either the character input by the user from the keyboard or the character value of the pressed key. To retrieve a value from this property, the tbeOnKeyUp and tbeOnKeyDown events are used.

The tbeOnKeyDown event is triggered when a key is pressed on the keyboard, whereas the tbeOnKeyUp event is triggered when a pressed key is released on the keyboard. The clSenderKeyChar property of the form is used to perform operations based on the input received from the keyboard. This property holds the information about the pressed or released key in decimal format. If you are unfamiliar with the decimal equivalents of keyboard keys, you can easily find them by searching for 'Key Code Table'.

In the example below, an application has been created that displays a message related to the pressed key based on the event that will occur according to the pressed key.

Example

var
   Form1:TCLForm;
 
 void KeyDown
 {
   if (Form1.clSenderKeyChar == 32)
   {
     ShowMessage('Space Key Pressed');
   }
   else if (Form1.clSenderKeyChar == 119)
   {
     ShowMessage('W Key Pressed');
   }
 }
 
 void KeyUp
 {
   if (Form1.clSenderKeyChar == 97)
   {
     ShowMessage('The A key was released');
   }
   else if (Form1.clSenderKeyChar == 100)
   {
     ShowMessage('The D key was released');
   }
 }
 
 {
   Form1 = TCLForm.Create(Self);
   Form1.AddNewEvent(Form1, tbeOnKeyDown, 'KeyDown');
   Form1.AddNewEvent(Form1, tbeOnKeyUp, 'KeyUp')
   Form1.Run;
 }

See Also