From Clomosy Docs
The VirtualKeyboard property in Clomosy is a feature that allows mobile applications to control the virtual keyboard. It is used to perform operations such as displaying, hiding, or monitoring the state of the virtual keyboard on mobile devices.
It is an event triggered on the form. This event is triggered by objects that cause the keyboard to open (such as TclMemo, TclEdit).
INFORMATION
You can use the KeyboardType property to manage keyboard operations and simplify user input. This feature allows you to set a virtual keyboard layout suitable for the type of input. For more information and usage details, please refer to the relevant page.
The VirtualKeyboard feature is important in mobile applications to enhance the user experience and increase usability. By listening to keyboard events, it becomes possible to adjust interactions within the application according to the keyboard's state and respond accordingly.
There are two types of usage:
- tbeOnVirtualKeyboardShown: This event is triggered when the virtual keyboard becomes visible on the screen. It occurs when the keyboard is opened for the user to enter text. When a process is defined for this event, the corresponding procedure can be executed when the keyboard is shown.
Form1.AddNewEvent(Form1,tbeOnVirtualKeyboardShown,'Event to trigger'); //Form1 : TclForm
- tbeOnVirtualKeyboardHidden: This event is triggered when the virtual keyboard is hidden from the screen. It occurs when the keyboard is closed and disappears, allowing related actions to be performed.
Form1.AddNewEvent(Form1,tbeOnVirtualKeyboardHidden,'Event to trigger'); //Form1 : TclForm
Test it on mobile devices.
On a form, multiple properties can also be used in conjunction with virtual keyboard events.
| Feature | Use of | Definition |
|---|---|---|
| clVKBoundsWidth | Form1.clVKBoundsWidth; | It gives the keyboard width. |
| clVKBoundsHeight | Form1.clVKBoundsHeight; |
It gives the keyboard height. |
| clVKBoundsRight | Form1.clVKBoundsRight; | It gives the distance from the right edge of the keyboard to the right boundary of the screen (the coordinate of the right edge). |
| clVKBoundsLeft | Form1.clVKBoundsLeft; | It gives the distance from the left edge of the keyboard to the left boundary of the screen (the coordinate of the left edge). |
| clVKVisible | Form1.clVKVisible = False; //True | This property determines whether the virtual keyboard is visible or not. When the value is set to **False**, the keyboard is hidden, and the remaining part of the screen becomes accessible again. |
Example
var
MyForm : TclForm;
Edt1: TclEdit;
MyBtn : TclButton;
MyLyt : TclLayout;
void VirtualKeyboardShow;
{
MyLyt.Margins.Bottom = MyForm.clVKBoundsHeight;
//ShowMessage(MyForm.clVKBoundsHeight);
//ShowMessage(MyForm.clVKBoundsWidth);
//ShowMessage(MyForm.clVKBoundsRight);
//ShowMessage(MyForm.clVKBoundsLeft);
}
void VirtualKeyboardHidden;
{
MyLyt.Margins.Bottom = 0;
}
{
MyForm = TclForm.Create(Self);
MyForm.AddNewEvent(MyForm,tbeOnVirtualKeyboardShown,'VirtualKeyboardShow');
MyForm.AddNewEvent(MyForm,tbeOnVirtualKeyboardHidden,'VirtualKeyboardHidden');
MyLyt = MyForm.AddNewLayout(MyForm,'MyLyt');
MyLyt.Align = alClient;
Edt1 = MyForm.AddNewEdit(MyLyt,'Edt1','Click!');
Edt1.Align = AlMostBottom;
Edt1.Height = 50;
MyBtn = MyForm.AddNewButton(MyLyt,'MyBtn','Hide!');
MyBtn.Align = alBottom;
MyBtn.Margins.Bottom= 10;
MyBtn.Margins.Top= 10;
MyForm.Run;
}