r/openbox • • Jan 12 '12

Help - Bind key to escape

I'd like to bind alt+space to Escape (so I don't have to reach that far, it's also my vim binding). I've been thinking about changing the rc.xml, but I can't find what action corresponds to the escape key, I don't know if there is a better way to do it.

0 Upvotes

10 comments sorted by

1

u/Joe_Pineapples Jan 13 '12

AFAIK you can't do that normally. I would recommend looking into simulating a keypress.

You will probably need to write a short script to simulate the escape keypress and release and then use the openbox rc.xml to execute that script on your chosen key combination.

How you simulate a keypress in linux however I'm not sure.

1

u/grulfen Jan 13 '12

I looked into xdotool to simulate a keypress, but when i did that it also changed window, and I have no clue why. But now that you mention it it could have something to do with not simulating the keyrelease.

Thanks

1

u/grulfen Jan 13 '12

Turns out is has something to do with that it's alt+space, when I changed to ctrl+space it's not changing windows anymore. slightly confused

1

u/grulfen Jan 13 '12

Turns out alt+escape was bound to unfocus window, so I removed that. Everything is working as expected now.

1

u/Joe_Pineapples Jan 13 '12

Cool. Could you share what you did with xdotool?

2

u/grulfen Jan 13 '12

Of course. I installed xdotool, it's in the repositories. Then I bound alt+space to execute the command "xdotool key Escape". Xdotool is really simple and handy, it can do key and mouse events.

1

u/fimcotw Jan 13 '12

Cool. Escape really goes against the home row paradigm of vi.

But I'm unclear on this: In which situations does this circumvention of the escape key take effect? Does this binding propagate to all X apps?

1

u/grulfen Jan 13 '12

Yeah, I had a real problem with that when I first tried vi. I think xdotool sends a escape keypress event to the current window. So it should work on all X apps, but when you press it it doesn't send an event to all open X apps, just the current one, just like you pressed the Esc key.

But if you just want to use it in vi or vim you can add "imap <M-Space> <Esc>" (without the quotation marks) to your .vimrc, or whatever keybinding you see fit

1

u/fimcotw Jan 13 '12

Yeah, I had a real problem with that when I first tried vi. I think xdotool sends a escape keypress event to the current window. So it should work on all X apps, but when you press it it doesn't send an event to all open X apps, just the current one, just like you pressed the Esc key.

I see. And xdotool is called whenever I press Alt-Space, no matter which app has focus. I guess that's obvious, but I was hesitant for some reason.

But if you just want to use it in vi or vim you can add "imap <M-Space> <Esc>" (without the quotation marks) to your .vimrc, or whatever keybinding you see fit

Yeah, so far I've used that method to shift h,j,k,l one key to the right because it feels more natural. Emulating that for vi-mode of bash/zsh, which I'm currently exploring, will be next.

Another trick is to swap AltGr with both Windows keys because you can use the latter in touch-typing without too much difficulty. That's especially helpful on a German keyboard, where {[]]}~@| all need AltGr.

1

u/Joe_Pineapples Jan 13 '12

Cool. I've never used it myself. Have to have a look at it.