From Clomosy Docs

No edit summary
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
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.
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
Form1.clSenderKeyChar : Integer;
</div>


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 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 - tbeOnKeyDown and tbeOnFormKeyUp - tbeOnFormKeyDown events are used.<br>


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.
The tbeOnKeyDown (tbeOnFormKeyDown) event is triggered when a key is pressed on the keyboard, whereas the tbeOnKeyUp (tbeOnFormKeyUp) 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'.<br>


'''Example:'''<br>
In the examples 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.<br>


:'''TRObject Syntax:'''


  var
<b>Example 1 - Usage of tbeOnKeyDown and tbeOnKeyUp </b><br>
    Form1:TCLForm;
 
    
<pre>
  void KeyDown
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;
}
</pre>
 
<b>Example 2 - Usage of tbeOnFormKeyDown and tbeOnFormKeyUp </b><br>
 
<pre>
var
   Form1:TCLForm;
void KeyDown
{
  if (Form1.clSenderKeyChar == 32)
  {
    ShowMessage('Space Key Pressed');
  }
  else if (Form1.clSenderKeyChar == 119)
   {
   {
     if (Form1.'''clSenderKeyChar''' == 32)
     ShowMessage('W Key Pressed');
    {
      ShowMessage('Space Key Pressed');
    }
    else if (Form1.'''clSenderKeyChar''' == 119)
    {
      ShowMessage('W Key Pressed');
    }
   }
   }
 
}
  void KeyUp
void KeyUp
{
  if (Form1.clSenderKeyChar == 97)
   {
   {
     if (Form1.'''clSenderKeyChar''' == 97)
     ShowMessage('a Key Pressed');
    {
      ShowMessage('The A key was released');
    }
    else if (Form1.'''clSenderKeyChar''' == 100)
    {
      ShowMessage('The D key was released');
    }
   }
   }
    
   else if (Form1.clSenderKeyChar == 100)
   {
   {
     Form1 = TCLForm.Create(Self);
     ShowMessage('d Key Pressed');
    Form1.AddNewEvent(Form1, '''tbeOnKeyDown''', 'KeyDown');
    Form1.AddNewEvent(Form1, '''tbeOnKeyUp''', 'KeyUp')
    Form1.Run;
   }
   }
}
{
  Form1 = TCLForm.Create(Self);
  Form1.AddNewEvent(Form1, tbeOnFormKeyDown, 'KeyDown');
  Form1.AddNewEvent(Form1, tbeOnFormKeyUp, 'KeyUp');
  Form1.Run;
}
</pre>
<h2> See Also </h2>
* [[System_Library#Cl_Utilities_Functions | Cl Utilities Functions]]


:'''Base Syntax'''
{{#seo:|description=Learn about ClSenderKeyChar in Clomosy. Capture and manage key press events to enhance input handling and interaction in your mobile apps.}}
  var
    Form1:TCLForm;
 
  procedure KeyDown
  begin
    if Form1.'''clSenderKeyChar''' = 32 then
    begin
      ShowMessage('Space Key Pressed');
    end
    else if Form1.'''clSenderKeyChar''' = 119 then
    begin
      ShowMessage('W Key Pressed');
    end;
  end;
 
  procedure KeyUp
  begin
    if Form1.'''clSenderKeyChar''' = 97 then
    begin
      ShowMessage('The A key was released');
    end
    else if Form1.'''clSenderKeyChar''' = 100 then
    begin
      ShowMessage('The D key was released');
    end;
  end;
 
  begin
    Form1 := TCLForm.Create(Self);
    Form1.AddNewEvent(Form1, '''tbeOnKeyDown''', 'KeyDown');
    Form1.AddNewEvent(Form1, '''tbeOnKeyUp''', 'KeyUp')
    Form1.Run;
  end;

Latest revision as of 13:44, 20 February 2025

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 - tbeOnKeyDown and tbeOnFormKeyUp - tbeOnFormKeyDown events are used.

The tbeOnKeyDown (tbeOnFormKeyDown) event is triggered when a key is pressed on the keyboard, whereas the tbeOnKeyUp (tbeOnFormKeyUp) 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 examples 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 1 - Usage of tbeOnKeyDown and tbeOnKeyUp

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;
 }

Example 2 - Usage of tbeOnFormKeyDown and tbeOnFormKeyUp

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('a Key Pressed');
  }
  else if (Form1.clSenderKeyChar == 100)
  {
    ShowMessage('d Key Pressed');
  }
}
{
  Form1 = TCLForm.Create(Self);
  Form1.AddNewEvent(Form1, tbeOnFormKeyDown, 'KeyDown');
  Form1.AddNewEvent(Form1, tbeOnFormKeyUp, 'KeyUp');
  Form1.Run;
}

See Also