Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-28-2007, 01:16 PM   #1
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,826

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
Need help with guile and xbindkeys

I've recently discovered how to configure my extra Kensington Expert Mouse trackball buttons using xbindkeys, as detailed in this thread. I've even discovered that it's possible to define mouse chords (mouse button combos, a feature I loved in Kensington's Windows driver), using xbindkeys' guile support. I need to make some changes to the configuration, , however, and I don't know enough (well, anything really) about guile to do it.

As I explained in the other thread, the example config file includes a guile function for defining chording actions. You can define it to run a different commands for each of four actions. b1 alone, b2 alone, b1 then b2, and b2 then b1. b1-b4 being any button, key, button+modifier, or key+modifier.

This works generally, but I have two problems with it as defined.

First, it doesn't detect the chord actions consistently (for my mouse and clicking style at least). It only seems to perform the correct action about once in every 8 or 10 tries. I need to modify it to accept a longer delay in clicking or something so that it detects the actual actions more consistently.

Second, the script blocks the original actions of whatever buttons you define. For example, if I try to set button3+button6 so that it starts an xterm, then right now I lose all other button3 (right-click) functionality in the process. Now this isn't a problem for the buttons above the basic 5, which don't have default actions, or if I define a modifier key, like "shift+button3+button6", but I want to be able to define any of the buttons to actions without modifiers and without losing their original functions. So I need to modify the script so that the default function is able to pass through when an action is undefined. Or even better make it so that it only captures the actions when in combo, and let me define individual button actions separately elsewhere in the config file.

Sorry if this is getting long and hard to follow. I want to make sure I'm expressing the problems clearly.

To summarize, I need:

1: A configuration that lets you set up two-button mouse chords, such as b1+b3, without affecting the actions of the buttons individually.

2: To modify the scripts so that the button combos are more consistently detected perhaps with better-defined click delays or release events.

I'll appreciate any help I can get.

Here's the sample xmodkeysrc.scm file they include. The chording script is at the end.

;; Start of xbindkeys guile configuration ;;
;; This configuration is guile based.
;; any functions that work in guile will work here.

;; Version: 1.8.2

;; If you edit this file, do not forget to uncomment any lines
;; that you change.
;; The semicolon(;) symbol may be used anywhere for comments.

;; To specify a key, you can use 'xbindkeys --key' or
;; 'xbindkeys --multikey' and put one of the two lines in this file.

;; A list of keys is in /usr/include/X11/keysym.h and in
;; /usr/include/X11/keysymdef.h
;; The XK_ is not needed.

;; List of modifier:
;;   Release, Control, Shift, Mod1 (Alt), Mod2 (NumLock),
;;   Mod3 (CapsLock), Mod4, Mod5 (Scroll).

;; The release modifier is not a standard X modifier, but you can
;; use it if you want to catch release instead of press events

;; By defaults, xbindkeys does not pay attention to modifiers
;; NumLock, CapsLock and ScrollLock.
;; Uncomment the lines below if you want to use them.
;; To dissable them, call the functions with #f

;;;;EXTRA FUNCTIONS: Enable numlock, scrolllock or capslock usage
;;(set-numlock! #t)
;;(set-scrolllock! #t)
;;(set-capslock! #t)

;;;;; Scheme API reference
;; Optional modifier state:
;; (set-numlock! #f or #t)
;; (set-scrolllock! #f or #t)
;; (set-capslock! #f or #t)
;; Shell command key:
;; (xbindkey key "foo-bar-command [args]")
;; (xbindkey '(modifier* key) "foo-bar-command [args]")
;; Scheme function key:
;; (xbindkey-function key function-name-or-lambda-function)
;; (xbindkey-function '(modifier* key) function-name-or-lambda-function)
;; Other functions:
;; (remove-xbindkey key)
;; (run-command "foo-bar-command [args]")
;; (grab-all-keys)
;; (ungrab-all-keys)
;; (remove-all-keys)
;; (debug)

;; Examples of commands:

(xbindkey '(control shift q) "xbindkeys_show")

;; set directly keycode (here control + f with my keyboard)
(xbindkey '("m:0x4" "c:41") "xterm")

;; specify a mouse button
(xbindkey '(control "b:2") "xterm")

;;(xbindkey '(shift mod2 alt s) "xterm -geom 50x20+20+20")

;; set directly keycode (control+alt+mod2 + f with my keyboard)
(xbindkey '(alt "m:4" mod2 "c:0x29") "xterm")

;; Control+Shift+a  release event starts rxvt
;;(xbindkey '(release control shift a) "rxvt")

;; Control + mouse button 2 release event starts rxvt
;;(xbindkey '(releace control "b:2") "rxvt")

;; Extra features
(xbindkey-function '(control a)
                   (lambda ()
                     (display "Hello from Scheme!")

(xbindkey-function '(shift p)
                   (lambda ()
                     (run-command "xterm")))

;; Double click test
(xbindkey-function '(control w)
                   (let ((count 0))
                     (lambda ()
                       (set! count (+ count 1))
                       (if (> count 1)
                            (set! count 0)
                            (run-command "xterm"))))))

;; Time double click test:
;;  - short double click -> run an xterm
;;  - long  double click -> run an rxvt
(xbindkey-function '(shift w)
                   (let ((time (current-time))
                         (count 0))
                     (lambda ()
                       (set! count (+ count 1))
                       (if (> count 1)
                            (if (< (- (current-time) time) 1)
                                (run-command "xterm")
                                (run-command "rxvt"))
                            (set! count 0)))
                       (set! time (current-time)))))

;; Chording keys test: Start differents program if only one key is
;; pressed or another if two keys are pressed.
;; If key1 is pressed start cmd-k1
;; If key2 is pressed start cmd-k2
;; If both are pressed start cmd-k1-k2 or cmd-k2-k1 following the
;;   release order
(define (define-chord-keys key1 key2 cmd-k1 cmd-k2 cmd-k1-k2 cmd-k2-k1)
    "Define chording keys"
  (let ((k1 #f) (k2 #f))
    (xbindkey-function key1 (lambda () (set! k1 #t)))
    (xbindkey-function key2 (lambda () (set! k2 #t)))
    (xbindkey-function (cons 'release key1)
                       (lambda ()
                         (if (and k1 k2)
                             (run-command cmd-k1-k2)
                             (if k1 (run-command cmd-k1)))
                         (set! k1 #f) (set! k2 #f)))
    (xbindkey-function (cons 'release key2)
                       (lambda ()
                         (if (and k1 k2)
                             (run-command cmd-k2-k1)
                             (if k2 (run-command cmd-k2)))
                         (set! k1 #f) (set! k2 #f)))))

;; Example:
;;   Shift + b:1                   start an xterm
;;   Shift + b:3                   start an rxvt
;;   Shift + b:1 then Shift + b:3  start gv
;;   Shift + b:3 then Shift + b:1  start xpdf

(define-chord-keys '(shift "b:1") '(shift "b:3")
  "xterm" "rxvt" "gv" "xpdf")

;; Here the release order have no importance
;; (the same program is started in both case)
(define-chord-keys '(alt "b:1") '(alt "b:3")
  "gv" "xpdf" "xterm" "xterm")

;; End of xbindkeys guile configuration ;;
The last command is what I've been using so far. I've replaced the original with the following for testing (running 'xmodkeys -n' in a terminal lets you watch the output):

(define-chord-keys '(b:6) '(b:7) "echo command1" "echo command2" "echo command3" "echo command3")

When everything works correctly, I get command3 when I click both b6 and b7 together. But it only works occasionally. Usually I get command1 or command2 only. And of course if I redefine it to b:3 and b:6, then I can't use b:3 at all outside of the functions defined above.

[[Edited: What a doofus I am. I mistakenly wrote 'glade' when I wanted to say guile.]]

Last edited by David the H.; 10-30-2007 at 12:35 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with xbindkeys monkiidansu Linux - Software 1 08-14-2007 02:10 PM
XBindKeys 1.7.3 compile error cybi Linux - Software 4 08-31-2006 02:58 AM
Anything like xbindkeys to Windows XP? Mega Man X General 6 08-14-2006 11:54 AM
xbindkeys: How to get name of clicked program lagu2653 Linux - Software 1 06-27-2005 05:28 AM
xbindkeys - some keys unbindable? fr0zen Linux - Software 0 12-25-2003 08:11 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:47 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration