I need to know how to inject a KeySym
into the X Server using xcb
, xtest
or xlib
. I can inject keycodes, also get the keyboard mapping, search for a keysym there and press the according keycode, but i cannot inject a KeySym (eg XKB_KEY_Arabic_0
) when its not mapped to the current layout.
Is there a way I can do that?
What I thought of is find an empty keycode and remap it to the desired keysym. Problem: My code doesnt find an empty key. This is my code:
uint32_t find_empty_key_for_remapping()
{
int keycode_low;
int keycode_high;
KeySym * keysyms = 0;
int empty_key = 0;
int num_keysym;
XDisplayKeycodes(display_, &keycode_low, &keycode_high);
keysyms = XGetKeyboardMapping(display_, keycode_low, keycode_high - keycode_low, &num_keysym);
for (int i = keycode_low; i <= keycode_high && !empty_key; ++i)
{
bool key_is_empty = true;
for (int j = 0; j < num_keysym; ++j)
{
int symindex = ((i - keycode_low) * num_keysym) + j;
if (keysyms[symindex] != 0)
{
key_is_empty = false;
}
}
if (key_is_empty)
{
return i;
}
}
return 0;
}
Any help will be appreciated!
Injecting keysyms is done with xdotool
. To insert XKB_KEY_Arabic_0
use
xdotool key Arabic_0
which is independent of the keyboard mapping.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.