Xfce Forum

Sub domains

You are not logged in.

#1 2010-02-03 17:01:58

Registered: 2010-02-03
Posts: 3

Use CapsLock to switch focus, but keep <Alt>Tab


I want to do the following and hope for some help in how to do it.

I never use the caps lock key for typing in all-uppercase (who does that, anyways) and so I want to use it for something else (it's a pretty big key in a pretty prominent position, after all).

I already know how to turn off the caps lock functionality by running

xmodmap -e "clear Lock"

Now I can assign it to something different, like to "Next Workspace" in Xfce4's Settings -> Window Manager -> Keyboard. Works great.

What I actually would like to use it for, however, is to quickly switch back and forth between two windows, because I find myself hitting <Alt>Tab real fast very often. I would like to keep <Alt>Tab *as well*, though, because sometimes I want to switch to some other window and actually look at the little  application switching screen that pops up when you keep holding Alt.

One way to do it would be to have multiple shortcuts (<Alt>Tab and CapsLock) for "Cycle Windows". AFAICT, Xfce4 does not allow that. Am I wrong?

Another way would be some command line tool that allows to switch focus to the last active window, such that I can assign an application shortcut in Settings -> Keyboard -> Application Shortcuts to that command.
I don't know of such a command line tool, however. I have looked at wmctrl and some of the things that come with X, but to no avail. The main problem seems to be to tell which was the last active window.

Anybody any ideas on how to achieve what I want?


#2 2010-02-10 15:17:31

Registered: 2010-02-03
Posts: 3

Re: Use CapsLock to switch focus, but keep <Alt>Tab

Well, I found a workaround.

#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>

int main()
   Display *display;
   unsigned int keycodeAlt, keycodeTab;
   display = XOpenDisplay(NULL);
   keycodeAlt = XKeysymToKeycode(display, XK_Alt_L);
   keycodeTab = XKeysymToKeycode(display, XK_Tab);
   /* press alt */
   XTestFakeKeyEvent(display, keycodeAlt, True, 0);
   /* press tab */
   XTestFakeKeyEvent(display, keycodeTab, True, 100);
   /* release tab */
   XTestFakeKeyEvent(display, keycodeTab, False, 0);
   /* release alt */
   XTestFakeKeyEvent(display, keycodeAlt, False, 50);

   return 0;

Save this as e.g. myalttab.c then compile with gcc -lX11 -lXtst -o myalttab myalttab.c (I had to sudo apt-get install libxtst-dev first).

This program "simulates" you pressing <Alt>Tab, so binding the CapsLock key to the resulting executable yields what I was after.

Those delays (50 and 100 milliseconds) seem to be required, if they are shorter it doesn't work. This way you see Xfce's little application switching screen for a split second, which is not optimal. But I guess it works...


#3 2010-03-28 13:32:55

boer Krelis
Registered: 2009-02-18
Posts: 4

Re: Use CapsLock to switch focus, but keep <Alt>Tab

I want to do the same. Switch to last active window, I mean.
I'm using the same approach (workaround) as you are, except I use

xte 'keydown Alt_L' 'key Tab' 'keyup Alt_L'

to simulate the alt+tab keypresses. You can find xte in the xautomation package.

I'd love it if XFCE would gain a 'switch to last active window' action to assign a keyboard shortcut to.


#4 2010-03-28 15:07:13

boer Krelis
Registered: 2009-02-18
Posts: 4

Re: Use CapsLock to switch focus, but keep <Alt>Tab

Weird, it (xte) only works properly from a shell in this case. I guess it's got something with the delays you mentioned, but it doesn't even work when running something like

xte "keydown Alt_L" "key Tab" "usleep 100" "keyup Alt_L" "usleep 50"

Using your C program now. Thanks!


Board footer

Powered by FluxBB