16

This is the biggest thing keeping me from enjoying Ubuntu/Linux.

Ideally I'd like to just be able to run my AutoHotKey script on Ubuntu, but I didn't have much luck getting that working with Wine.

Here's what I'm doing in AHK (using extra modifiers also works, Shift+Alt+l is Shift+right).

!l:: Send, {Right}
+!l:: Send, +{Right}
^!l:: Send, ^{Right}
^+!l:: Send, ^+{Right}

I tried AutoKey, but it wasn't consuming input, remapping Alt + I to right arrow key worked, but it still executed Alt + I, which sometimes selects an item from the application menu.

The closest I got was xbindkeys for setting up hotkeys, this seems to work great. And xvkbd for simulating input; this part is really buggy; it doesn't work in all programs, and causes me to lose focus a lot, among other issues.

For anyone wondering what I'm trying to do: I use I J K L as arrow keys while Alt is down.

Kevin Bowen
  • 19,395
  • 55
  • 76
  • 81
Farzher
  • 285
  • 1
  • 4
  • 14

1 Answers1

19

I've never used xvkbd, but there are two other great programs for simulating keyboard input that I like and use. One is xte and the other is xdotool.

sudo apt-get install xautomation xdotool  

Both xdotool and xte are very similar, but since I use xte the most I'll go into that one.

xte:

The most basic syntax for xte is:

xte 'command key/mousebutton/xyCoordinates'

xte can do a lot more than just create keyboard input though, it can also move your mouse and simulate mouse button presses, among others things.

Syntax examples:

  • To call a single key press: xte 'key keyName'

  • To call a key combination: xte 'keydown keyName' 'keydown secondKeyName' 'keyup keyName' 'keyup secondKeyName

  • To call a mouse button: xte 'mouseclick buttonNumber' (You can find button numbers through xev)

  • To move the mouse: xte 'mousemove xCoordinate yCoordinate'

  • And more! Read man xte

Keynames:

Here are a list of key names (other than the obvious ones):

Home
Left
Up
Right
Down
Page_Up
Page_Down
End
Return
BackSpace
Tab
Escape
Delete
Shift_L
Shift_R
Control_L
Control_R
Meta_L
Meta_R
Alt_L
Alt_R
Multi_key  
Super_L  
Super_R

Reading:

You might also be interested in reading:

How can I change what keys on my keyboard do? (How can I create custom keyboard commands/shortcuts?)

How do I remap certain keys or devices?

Seth
  • 57,282
  • 43
  • 144
  • 200
  • This looks good but it's not working with `xbindkeys`. When `xte 'key a'` is called from `xbindkeys` it just makes my cursor flash when I press my hotkey. `xte 'key a'` in the command line works. `gnome-terminal` called from `xbindkeys` works. I'm not sure where the problem is. – Farzher May 01 '13 at 22:46
  • It really don't seem like `xte` is trying to send the key event to the focused window when called from `xbindkeys`... – Farzher May 01 '13 at 22:48
  • @StephenSarcsamKamenar I myself have had some trouble, but from my experience that has been `xbindkeys` problem.. For me I have to press the key combination at *exactly* the same time to get `xbindkeys` to send the command. YMMV. – Seth May 02 '13 at 02:52
  • Maybe an `xbindkeys` problem; `xdotool` worked with it, but when I held down a key, it would never repeat it. What are good alternatives to `xbindkeys`? – Farzher May 02 '13 at 04:19
  • 1
    @StephenSarcsamKamenar Xmodmap is explained in [this](http://askubuntu.com/questions/24916/how-do-i-remap-certain-keys/) answer as well as [this](http://askubuntu.com/a/257497/44179) one. That's what I'd use if `xbindkeys` didn't preform well enough (which it doesn't with xte.. at least for me.) – Seth May 03 '13 at 00:44
  • `xmodmap` only supports single buttons it looks like. I need to rebind `alt + i` – Farzher May 04 '13 at 05:17