LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

Reply
 
Search this Thread
Old 09-20-2012, 07:25 PM   #1
Zero Angel
Member
 
Registered: Jul 2010
Distribution: PinguyOS 12.04
Posts: 50

Rep: Reputation: 1
[xbindkeys] Advanced mouse binds?


I have a logitech mouse with some extra buttons on it. Previously I installed xbindkeys and set it up so that b:8 and b:9 (the shoulder buttons) on the mouse changed workspaces (well, emulated some keypresses).

Code:
"xdotool key --clearmodifiers ctrl+alt+Down"
b:8
"xdotool key --clearmodifiers ctrl+alt+Up"
b:9
But now I want to get even more jazzier with it.

I want to have it set up so that b:8 acts as a modifer to my scrollwheel. So that if I scroll while holding down one of the shoulder buttons, it will change my workspace in the direction that I scroll. And I want to set it up so that when I hold the other shoulder button and use the scrollwheel it will activate the flip switcher.

Now here's the clincher. xbindkeys doesnt appear to support multiple mouse keys to perform a single action. I tried to make my .xbindkeysrc contain the following:
Code:
"xdotool key --clearmodifiers ctrl+alt+Down"
    b:9 + b:4 
"xdotool key --clearmodifiers ctrl+alt+Up"
    b:9 + b:5
However this causes all kind of weird effects like causing the ctrl or alt modifiers to turn 'on' and not turn off. And meanwhile the command wont execute.

Does anyone know how to do what i'm trying to do?

Last edited by Zero Angel; 09-20-2012 at 08:49 PM.
 
Old 09-20-2012, 10:21 PM   #2
Zero Angel
Member
 
Registered: Jul 2010
Distribution: PinguyOS 12.04
Posts: 50

Original Poster
Rep: Reputation: 1
I figured it out on my own. After hours of searching, I realized that the default .xbindkeysrc file syntax could not do sophisticated enough logic to handle multiple mouse keys, however it did mention that it supported the guile scripting language so after more searching I stumbled upon this guide:

http://computers-stuff.blogspot.ca/2...nf-file-i.html


Using that guide I managed to make xbindkeys perform these functions:
  • Front shoulder button (b9) + Scrollwheel emulates CTRL+ALT+UP/DOWN
  • Rear shoulder button (b8) + Scrollwheel emulates ALT+TAB and ALT+SHIFT+TAB

The file is as follows

~/.xbindkeysrc.scm [OBSOLETE: See next post]
Code:
;;   This configuration is guile based.
;;   http://www.gnu.org/software/guile/guile.html
;;   This config script us supposed to live in the homedirectory.
;;   This was a not so quick but probably yet dirty hack by Zero Angel
;;   You'll need xdotool and xbindkeys with -guile support compiled for this to work (The Ubuntu xbindkeys will have this support by default).
;;   This is heavily based on Vee Lee's configuration file
;;   It assigns keybindings to the scroll wheel  on the fly when mouse modifier keys are pressed. Useful for mice with lots of buttons!

(define (first-binding)
"First binding"
;; Logitech Front Shoulder Button
(xbindkey-function '("b:9") b9-second-binding)
;; Logitech Rear Shoulder Button
(xbindkey-function '("b:8") b8-second-binding)
)


(define (reset-first-binding)
"reset first binding"
(ungrab-all-keys)
(remove-all-keys)
(first-binding)
(grab-all-keys))


(define (b9-second-binding)
"Front Shoulder Button Extra Functions"
(ungrab-all-keys)
(remove-all-keys)

;; Scroll Up
(xbindkey-function '("b:4")
                (lambda ()
                   (run-command "xdotool key --clearmodifiers ctrl+alt+Up&")
))

;; Scroll Down
(xbindkey-function '("b:5")
                (lambda ()
                  (run-command "xdotool key --clearmodifiers ctrl+alt+Down&")
))

(xbindkey-function '(release "b:9") (lambda ()
 (run-command "echo -e 'Placeholder for button release command' &")
(reset-first-binding)))
(grab-all-keys))

(define (b8-second-binding)
"Rear Shoulder Button Extra Functions"
(ungrab-all-keys)
(remove-all-keys)

;; Scroll Up
(xbindkey-function '("b:4")
                (lambda ()
                   (run-command "xdotool key --clearmodifiers alt+shift+tab&")
))

;; Scroll Down
(xbindkey-function '("b:5")
                (lambda ()
                  (run-command "xdotool key --clearmodifiers alt+tab&")
))

(xbindkey-function '(release "b:8") (lambda ()
 (run-command "echo -e 'Placeholder for button release command'&")
(reset-first-binding)))
(grab-all-keys))

;; (define (scroll-apps-binding)
;; "scroll-apps-binding"
;; (ungrab-all-keys)
;; (remove-all-keys)
;; (xbindkey-function '("b:4")(run-command "echo -e 'KeyStrPress Tab\nKeyStrRelease Tab' | xmacroplay :0 &"))
;; (xbindkey-function '("b:5")(run-command "echo -e 'KeyStrPress Shift_L\nKeyStrPress Tab\nKeyStrRelease Tab\nKeyStrRelease Shift_L' | xmacroplay :0 &"))
;; (xbindkey-function '("b:1") reset-first-binding)
;; (grab-all-keys))
;; (debug)
(grab-all-keys)
(first-binding)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End of xbindkeys configuration ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
It can be a little buggy sometimes though. Not releasing the modifier keys that it uses. However this is basic, and I can always repurpose the emulation to windowmanager-specific DBUS commands that accomplish the same thing.

Last edited by Zero Angel; 09-22-2012 at 06:47 PM.
 
Old 09-22-2012, 06:43 PM   #3
Zero Angel
Member
 
Registered: Jul 2010
Distribution: PinguyOS 12.04
Posts: 50

Original Poster
Rep: Reputation: 1
Improved the script.

- Modifier keys will no longer get stuck as they are forcefully released
- Can properly handle events where the shoulder buttons are pressed by themselves (no scrollwheel used).

.xbindkeysrc.scm
Code:
;;   This configuration is guile based.
;;   http://www.gnu.org/software/guile/guile.html
;;   This config script is supposed to live in the homedirectory.
;;   Awesome script created by Zero Angel
;;   This couldnt have been possible without seeing Vee Lee's configuration file
;;   You'll need xdotool and xbindkeys with -guile support compiled for this to work (The Ubuntu xbindkeys will have this support by default).
;;   It assigns keybindings to the scroll wheel  on the fly when mouse modifier keys are pressed. Useful for mice with lots of buttons!
;;   v1.0 -- Shoulder button + scrollwheel bindings
;;   v1.1 -- Fixes some 'stuckness' problems with the modifer keys (ctrl, alt, shift)
;;   v1.2 -- Can trigger events properly if the modifier button is simply pressed and released by itself. Forcefully clears modifier keys when the shoulder buttons are depressed.

(define actionperformed 0)

(define (first-binding)
"First binding"
;; Logitech Front Shoulder Button
(xbindkey-function '("b:9") b9-second-binding)
;; Logitech Rear Shoulder Button
(xbindkey-function '("b:8") b8-second-binding)
)


(define (reset-first-binding)
"reset first binding"
(ungrab-all-keys)
(remove-all-keys)
;; Set Action Performed state back to 0
(set! actionperformed 0)
;; Forcefully release all modifier keys!
(run-command "xdotool keyup ctrl keyup alt keyup shift keyup super&")

(first-binding)
(grab-all-keys))


(define (b9-second-binding)
"Front Shoulder Button Extra Functions"
(ungrab-all-keys)
(remove-all-keys)

;; Scroll Up
(xbindkey-function '("b:4")
                (lambda ()
;; Emulate Ctrl+Alt+Up (Workspace Up)
                (run-command "xdotool keydown ctrl keydown alt key Up keyup ctrl keyup alt&")
		(set! actionperformed 1)
))

;; Scroll Down
(xbindkey-function '("b:5")
                (lambda ()
;; Emulate Ctrl+Alt+Down (Workspace Down)
                (run-command "xdotool keydown ctrl keydown alt key Down keyup ctrl keyup alt&")
		(set! actionperformed 1)
))

(xbindkey-function '(release "b:9") (lambda ()
;; Perform Action if Button 8 is pressed and released by itself
(if (= actionperformed 0) (run-command "zenity --info --title=hi --text=Button9ReleaseEvent &"))
(reset-first-binding)))
(grab-all-keys))

(define (b8-second-binding)
"Rear Shoulder Button Extra Functions"
(ungrab-all-keys)
(remove-all-keys)

;; Scroll Up
(xbindkey-function '("b:4")
                (lambda ()
;; Emulate Alt+Shift+Tab (previous window)
                (run-command "xdotool keydown alt keydown shift key Tab keyup alt keyup shift")
		(set! actionperformed 1)
))

;; Scroll Down
(xbindkey-function '("b:5")
                (lambda ()
;; Emulate Alt+Tab (next window)
                (run-command "xdotool keydown alt key Tab keyup alt")
		(set! actionperformed 1)
))

(xbindkey-function '(release "b:8") (lambda ()
;; Perform Action if Button 8 is pressed and released by itself
     (if (= actionperformed 0) (run-command "zenity --info --title=hi --text=Button8ReleaseEvent &"))
(reset-first-binding)
))
(grab-all-keys)
)

;; (debug)
(first-binding)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End of xbindkeys configuration ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Last edited by Zero Angel; 09-22-2012 at 09:59 PM.
 
Old 09-23-2012, 05:40 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Interesting. I use a big Kensington trackball myself and I've been wanting to do something similar for a long time. I even posted something a few years ago about it (since I don't have guile experience) but got no answers (possibly because I screwed up the title for it. )

I'm going to be too busy this week to try it out right away, but I'm certainly going to look into it when I have the time. Thanks.
 
  


Reply


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
Is there a service that binds and listens to unused ports? unraisedarc Linux - Newbie 4 07-08-2010 01:50 AM
mouse binds for interactive desktop AlteRFirE Suse/Novell 4 01-12-2007 11:54 PM
HP ps/2 optical mouse , advanced help needed jellyini Ubuntu 7 10-23-2006 04:05 PM
Red Hat Enterprise 3 AS Binds Config Different louisb Linux - Enterprise 2 02-14-2005 01:27 PM
binds moonspell *BSD 2 12-11-2003 06:59 PM


All times are GMT -5. The time now is 04:36 PM.

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