Keyboard automation
Contents |
environment
o.s. = debian stretch (this will work with any linux)
xserver = xserver-xorg-core 2:1.19.2-1+deb9u5
xdotool = 1:3.20160805.1-3
problem
need to program keyboard keys (macros) to send keyboard input or launch programs
solution
install xdotool and configure
"snooping" keyboard input keycodes
in a terminal run program xev (comes with xserver-xorg-core i think) and then just hit the keyboard key of interest. you will see output such as...
KeyPress event, serial 37, synthetic NO, window 0x3600001, root 0x4a0, subw 0x0, time 9652301, (164,120), root:(2235,492), state 0x10, keycode 133 (keysym 0xffeb, Super_L), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False
make a note of the state and keycode which are to be input into the xdotool config
example keyboard input
here we will program the "windows" key (between left ctrl and alt) to send "hahah lol" text as if entered by the keyboard.
edit $HOME/.xbindkeysrc, add a section like the one below. first line is a comment, 2nd is the commands to execute, 3rd line is the keycode line where 0x10 is from the state above and 133 is the keycode.
## "windows" key macro "sleep 0.2 && xdotool type --delay 15 'hahaha lol';" m:0x10 + c:133
save .xbindkeysrc
start or restart xbindkeys
$ killall xbindkeys; xbindkeys
in a terminal or text editor test you keyboard input by pressing you "windows key"
it should output... hahaha lol
example keyboard input
same steps as above, add the following section to $HOME/.xbindkeys (did this after installing screengrab). my printscreen keycode was 107, yours may be different.
- printscreen keyboard shortcut
"/usr/bin/screengrab"
m:0x10 + c:107
start or restart xbindkeys
test by hitting you printscreen button, hope it works!