single-key alt-tab

My device control program has been evolving.

Today I had the idea of attaching the desktop ‘alt-tab’ window switching behavior to a key on the controller. But since alt-tab generally relies on you holding down alt while pressing tab to cycle through the windows, how was this going to work with only a single key?

I quickly read up on threads in Ruby. So my controller code will ‘press down’ alt the first time you press the mapped key, but relies on a background thread tracking a small time delay to ‘lift up’ the key after you stop making presses. If you keep pressing the control key, it extends the delay. One slight enhancement is that it allows a different delay for the initial and subsequent key presses.

Anyway, my control script is now looking like this:

plugin 'Rhythmbox'
plugin 'XKeys'
plugin 'Mixer', :control => 'Front', :suffix => '%', :debug => true
plugin 'Utility'
plugin 'AltTab', :delay => 0.3, :initial => 0.7
 
device "/dev/input/by-id/usb-050d_0805-event-joystick"
 
rule 'KEY', 306, 1 do
        rhythmbox "play-pause"
end
rule 'KEY', 305, 1 do
        rhythmbox "previous"
end
rule 'KEY', 307, 1 do
        rhythmbox "next"
end
 
rule 'KEY', 311, 1 do
        alt_tab_press
end
 
rule 'ABS', 'X', 0 do
        key_press :ctrl, :alt, :left
end
 
rule 'ABS', 'X', 255 do
        key_press :ctrl, :alt, :right
end
 
rule 'ABS', 'THROTTLE' do |value|
        set_volume(adjust_range(value, 255, 0, 50, 90))
end

I’ve split out various behaviors into ‘plugins’ which can be loaded and configured, so the main code stays neater. There are some ‘method_missing’ type hacks in the core code so that plugin methods can be called without qualification, to keep the syntax simple.

So I now have: three keys set up to control Rhythmbox (music player); a key doing the ‘alt-tab’ call I’ve just been talking about; up and down on the directional pad switching workspaces; and the throttle control setting volume.

One Trackback

  1. By The Junction » ruter project on February 8, 2008 at 8:58 am

    […] The Junction Skip to content « single-key alt-tab […]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*