To generate a single keystroke or a combination of keys and send them to the window with the focus, you can use the SendKeys(..) method.
Syntax:
Static Sub SendKeys ( Keys As String )
Keys is a list of keys that are sent one after the other. The (formal) names of the keys are listed in the X11 header file /usr/include/X11/keysymdef.h. For example, you can use this command in a console to determine selected key names on the keypad:
hans@linux:~$ cat /usr/include/X11/keysymdef.h | grep 'KP_E' #define XK_KP_Enter 0xff8d /* Enter */ #define XK_KP_End 0xff9c #define XK_KP_Equal 0xffbd /* Equals */ hans@linux:~$
To extract a key name, remove the XK_ prefix from the constants in the /usr/include/X11/keysymdef.h file. The key labeled[1/End] in the numeric keypad has the key name KP_End - but only if the numeric keypad has been deactivated with the NumLock key - otherwise the digit 1 becomes effective.
Unfortunately, you do not see that the key names are case-sensitive and not always consistent. For example,' Return' starts with a large R, but the space bar with the key name' space' starts with a small s. In the file /usr/include/X11/keysymdef.h you will find the name XK_KP_Space, while the key analysis program xev describes the pressed space bar as 'space':
KeyRelease event, serial 33, synthetic NO, window 0x3400001, root 0xbc, subw 0x3400002, time 15995041, (33,37), root:(149,566), state 0x0, keycode 65 (keysym 0x20, space), same_screen YES, XLookupString gives 1 bytes: (20) " " XFilterEvent returns: False
The icing on the cake is a remark from Minisini about the changes in keyboard shortcuts:“X11 found it great to change the meaning of individual keys recently. Previously capital letters were used, now they use a mixture of upper and lower case letters. Very funny.”
For this reason only Desktop.SendKeys (“{[Control_L]c}”) with small c is working correctly!
Consider the differences in the names of the individual keys, as they differ from each other.
For example, to reach the question mark or backslash on a German keyboard in the alpha-numeric block, you have to switch to the 2nd or 3rd assignment of the german ß-key. The switch or modifier for the 2nd level is the Shift key and with the AltGr key (alternative graphic character set; key name: ISO_Level3_Shift) you get to the 3rd level and reach the backslash (→ \). The second assignment of the print key can usually be reached with the modifier Alt key, for example.
The syntax is quite simple, but some remarks are still needed:
Examples:
Desktop.SendKeys("A") « Desktop.SendKeys("{[Shift_L]a}") « Desktop.SendKeys("{[Shift_R]a}") Desktop.SendKeys("\n") « Desktop.SendKeys("[Return]") Desktop.SendKeys("{[Control_L]c}") Desktop.SendKeys("Gambas Almost Means BASic") Desktop.SendKeys(TextArea.Text) Desktop.SendKeys("{[Control_L]}{[Alt_L]}{[Print]}") ' Screenshot Desktop.SendKeys("{[Alt_L]}{[Print]}") ' Screenshot of the active window Desktop.SendKeys("[NumLock]") Desktop.SendKeys("[F1]")