LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 04-20-2011, 03:20 PM   #1
Vinter
Member
 
Registered: Feb 2005
Location: Germany
Distribution: Aptosid
Posts: 113

Rep: Reputation: 19
[xbindkeys] Mouse button as modifier


Hi!

As I'd like to be able to fully control my desktop with both my keyboard and my mouse, I wrote a .xbindkeysrc.scm script to make two of my eight mouse buttons work as modifiers. For instance, b:9 + wheel now changes volume.

Only problem is, I accomplish this by emulating a key press with a modifier held, and the modifier seems to stick randomly after the mouse buttons have been released.

I would be very happy if anyone could point out the errors in the script below (or with the software used, I don't know how reliable xvkbd is).

Code:
(define (display-n str)
  "Display a string then newline"
  (display str)
  (newline))

(define (ctrlpress key)
	"Press key with CTRL held"
	(run-command
		(string-append "xvkbd -text '\\[Control_L]\\[" key "]'")))
		
(define (altpress key)
	"Press key with Alt held"
	(run-command
		(string-append "xvkbd -text '\\[Alt_L]\\[" key "]'")))

(define (reset-to-primary-binding)
  "Reset primary binding"
  (ungrab-all-keys)
  (remove-all-keys)
  (primary-binding)
  (run-command "xdotool keyup shift")
  (run-command "xdotool keyup ctrl")
  (run-command "xdotool keyup alt")
  (grab-all-keys))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (primary-10)
  "Iconify"
  (ctrlpress "F1"))

(define (primary-11)
  "Close"
  (ctrlpress "F2"))

(define (primary-12)
  "Maximize"
  (ctrlpress "F3"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (secondary-1) ;;UNASSIGNED
  (display-n "secondary-1: Code Me"))

(define (secondary-2)
  "PlayPause"
  (altpress "F5"))

(define (secondary-3)
 "Show Desktop"
  (ctrlpress "F10"))

(define (secondary-4)
  "VolDown"
  (altpress "F3"))

(define (secondary-5)
  "VolUp"
  (altpress "F2"))

(define (secondary-8)
  (display-n "secondary-8: Code Me"))

(define (secondary-9)
  "Raise"
  (ctrlpress "F8"))

(define (secondary-10)
  (display-n "secondary-10: Code Me"))

(define (secondary-11)
  "Next"
  (altpress "F7"))

(define (secondary-12)
  "Prev"
  (altpress "F6"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (tertiary-1)
  "xterm"
  (run-command "xterm"))

(define (tertiary-2)
   "xterm"
  (run-command "xterm"))

(define (tertiary-3)
  "xterm"
  (run-command "xterm"))

(define (tertiary-4)
  (display-n "tertiary-4: Code Me"))
	
(define (tertiary-5)
  (display-n "tertiary-5: Code Me"))

(define (tertiary-8)
  "Lower"
  (ctrlpress "F9"))

(define (tertiary-9)
  (display-n "tertiary-9: Code Me"))

(define (tertiary-10)
  (display-n "tertiary-10: Code Me"))

(define (tertiary-11)
  (display-n "tertiary-11: Code Me"))

(define (tertiary-12)
  (display-n "tertiary-12: Code Me"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (primary-binding)
  "Bind all primary bindings"
  ;; 1 - 5 use the default action
  (xbindkey-function  '("b:8") second-binding)
  (xbindkey-function  '("b:9") tertiary-binding) 

  (xbindkey-function '("b:10") primary-10)
  (xbindkey-function '("b:11") primary-11)
  (xbindkey-function '("b:12") primary-12))

(define (second-binding) ;;bindings for the 8th button
  "Bind all secondary binding"
  (let ((modkey-used #f))
    (ungrab-all-keys)
    (remove-all-keys)
    (xbindkey-function '("b:1")
                       (lambda () (secondary-1)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:2")
                       (lambda () (secondary-2)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:3")
                       (lambda () (secondary-3)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:4")
                       (lambda () (secondary-4)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:5")
                       (lambda () (secondary-5)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:9")
                       (lambda () (secondary-9)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:10")
                       (lambda () (secondary-10)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:11")
                       (lambda () (secondary-11)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:12")
                       (lambda () (secondary-12)
                               (set! modkey-used #t)))
    (xbindkey-function '(release "b:8")
                       (lambda ()
                         (set! modkey-used #f)
                         (reset-to-primary-binding)))
   (grab-all-keys)))

(define (tertiary-binding) ;;bindings for the 9th button
  "Bind all tertiary binding"
  (let ((modkey-used #f))
    (ungrab-all-keys)
    (remove-all-keys)
    (xbindkey-function '("b:1")
                       (lambda () (tertiary-1)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:2")
                       (lambda () (tertiary-2)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:3")
                       (lambda () (tertiary-3)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:4")
                       (lambda () (tertiary-4)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:5")
                       (lambda () (tertiary-5)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:8")
                       (lambda () (tertiary-8)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:10")
                       (lambda () (tertiary-10)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:11")
                       (lambda () (tertiary-11)
                               (set! modkey-used #t)))
    (xbindkey-function '("b:12")
                       (lambda () (tertiary-12)
                               (set! modkey-used #t)))
    (xbindkey-function '(release "b:9")
                       (lambda ()
                         (set! modkey-used #f)
                         (reset-to-primary-binding)))
    (grab-all-keys)))


(debug)
(grab-all-keys)
(primary-binding)
To make it easier to read, if you know Scheme even less than me:

The first part declares some base functions for the keystrokes to be sent with xvkbd. Also, the function to reset the bindings on relesae of the modifier is here. (As you may see, I already tried to put in some code to specifically reset the modifiers, with no results.)
The second part contains the default bindings for buttons 10-12 when no modifier is held.
The third and fourth part specify the actions when modifiers are held, usually to send a keystroke or to run a command.
The fifth part performs the bindings for the first, second and third level.

Thanks for any advice,

Vinter

Last edited by Vinter; 04-20-2011 at 03:22 PM.
 
Old 04-21-2011, 03:07 AM   #2
lab-rat
LQ Newbie
 
Registered: Dec 2008
Distribution: Fedora Core 9, suse11.3 ,Ubuntu-super 10.10
Posts: 17

Rep: Reputation: 4
Vinter


Just a thought

Here :


(define (tertiary-5)
(display-n "tertiary-5: Code Me"))

(define (tertiary-8)
"Lower"
(ctrlpress "F9"))

(define (tertiary-9)
(display-n "tertiary-9: Code Me"))

(define (tertiary-10)
(display-n "tertiary-10: Code Me"))




(define (secondary-5)
"VolUp"
(altpress "F2"))

(define (secondary-8)
(display-n "secondary-8: Code Me"))

(define (secondary-9)
"Raise"
(ctrlpress "F8"))

(define (secondary-10)
(display-n "secondary-10: Code Me"))

(define (secondary-11)
"Next"
(altpress "F7"))

and then referring:


(set! modkey-used #t)))
(xbindkey-function '("b:4")
(lambda () (secondary-4)
(set! modkey-used #t)))
(xbindkey-function '("b:5")
(lambda () (secondary-5)
(set! modkey-used #t)))
(xbindkey-function '("b:9")
(lambda () (secondary-9)
(set! modkey-used #t)))
(xbindkey-function '("b:10")
(lambda () (secondary-10)
(set! modkey-used #t)))

OK these are Snips of the code you posted , BUT you made definitions for functions NOT used ,, and then INVOKED undefined functions for primary & tertiary functions later on ,, AND also; should not the REM'd out comments be outside of the definition frame ??


Recheck your code format and definition lists , ok


L-R
 
Old 04-21-2011, 03:11 AM   #3
lab-rat
LQ Newbie
 
Registered: Dec 2008
Distribution: Fedora Core 9, suse11.3 ,Ubuntu-super 10.10
Posts: 17

Rep: Reputation: 4
Oh good Grief
I hate windows servers

not sure what that banter is at the bottom of my last post , but it should have shown this

(xbindkey-function '("b:5")
(lambda () (tertiary-5)
(set! modkey-used #t)))
(xbindkey-function '("b:8")
(lambda () (tertiary-8)
(set! modkey-used #t)))
(xbindkey-function '("b:10")
(lambda () (tertiary-10)
(set! modkey-used #t)))
(xbindkey-function '("b:11")



now compare the frames for the defined and invoked functions


L-R
 
Old 04-21-2011, 03:13 AM   #4
lab-rat
LQ Newbie
 
Registered: Dec 2008
Distribution: Fedora Core 9, suse11.3 ,Ubuntu-super 10.10
Posts: 17

Rep: Reputation: 4
ok .this isn't working read the original post to see the deltas

I am not going to try retyping what is posted in the original post ,,
 
Old 04-24-2011, 02:43 AM   #5
Vinter
Member
 
Registered: Feb 2005
Location: Germany
Distribution: Aptosid
Posts: 113

Original Poster
Rep: Reputation: 19
Alright, I saw the extra functions and deleted them (no effect, of course), but what do you mean with the rest? I don't see any scope problems, and xbindkeys debug output does neither. Also, I could not find any invocation of an undefined function.
 
Old 04-24-2011, 03:27 AM   #6
Vinter
Member
 
Registered: Feb 2005
Location: Germany
Distribution: Aptosid
Posts: 113

Original Poster
Rep: Reputation: 19
Hm, I think I somehow advanced...

I replaced xvkbd with xdotool, and voila, it works without sticking keyboard modifiers - but now, the mouse modifiers themselves stick. This only happens after quite some time of usage (hours), but with no discernable reason. It seems that the "release" event is just not caught any more, I outfitted its function with debug output and it doesn't show.

This state cannot be cured, except by an X restart. I at least tried to restart xbindkeys and re-plug the mouse, couldn't think of anything else ^^ (Restarting hald or the like maybe? Didn't want to break my session.)

Here is my output:

Code:
vinter@frostbox:~$ xbindkeys -n -v
displayName = :0.0
rc file = /home/vinter/.xbindkeysrc
rc guile file = /home/vinter/.xbindkeysrc.scm
getting rc guile file /home/vinter/.xbindkeysrc.scm.
initializing guile fns...

min_keycode=8     max_keycode=255 (ie: know keycodes)
xbindkey_wrapper debug: key = b:8
xbindkey_wrapper debug: key = b:9
xbindkey_wrapper debug: key = b:10
xbindkey_wrapper debug: key = b:11
xbindkey_wrapper debug: key = b:12

min_keycode=8     max_keycode=255 (ie: know keycodes)
"(Scheme function)"
    m:0x0 + b:8   (mouse)
"(Scheme function)"
    m:0x0 + b:9   (mouse)
"(Scheme function)"
    m:0x0 + b:10   (mouse)
"(Scheme function)"
    m:0x0 + b:11   (mouse)
"(Scheme function)"
    m:0x0 + b:12   (mouse)
starting loop...
This is the same for both runs.

Now, the buggy output:

Code:
Button press !
e.xbutton.button=8
e.xbutton.state=16
"(Scheme function)"
    m:0x0 + b:8   (mouse)
got screen 0 for window 15a
xbindkey_wrapper debug: key = b:1
xbindkey_wrapper debug: key = b:2
xbindkey_wrapper debug: key = b:3
xbindkey_wrapper debug: key = b:4
xbindkey_wrapper debug: key = b:5
xbindkey_wrapper debug: key = b:9
xbindkey_wrapper debug: key = b:10
xbindkey_wrapper debug: key = b:11
xbindkey_wrapper debug: key = b:12
xbindkey_wrapper debug: modifier = release.
xbindkey_wrapper debug: key = b:8

min_keycode=8     max_keycode=255 (ie: know keycodes)
"(Scheme function)"
    m:0x0 + b:1   (mouse)
"(Scheme function)"
    m:0x0 + b:2   (mouse)
"(Scheme function)"
    m:0x0 + b:3   (mouse)
"(Scheme function)"
    m:0x0 + b:4   (mouse)
"(Scheme function)"
    m:0x0 + b:5   (mouse)
"(Scheme function)"
    m:0x0 + b:9   (mouse)
"(Scheme function)"
    m:0x0 + b:10   (mouse)
"(Scheme function)"
    m:0x0 + b:11   (mouse)
"(Scheme function)"
    m:0x0 + b:12   (mouse)
"(Scheme function)"
    Release + m:0x0 + b:8   (mouse)
Button release !
e.xbutton.button=8
e.xbutton.state=8208
^C
The output is simple: It detects that a button was pressed, then tells me twice in different formats what bindings have changed. A button release is detected at the end.

This is the clean output, I removed identical lines:

Code:
Button press !
e.xbutton.button=8
e.xbutton.state=0
[...]
Button release !
e.xbutton.button=8
e.xbutton.state=0
"(Scheme function)"
    Release + m:0x0 + b:8   (mouse)
got screen 0 for window 15a
released!
xbindkey_wrapper debug: key = b:8
xbindkey_wrapper debug: key = b:9
xbindkey_wrapper debug: key = b:10
xbindkey_wrapper debug: key = b:11
xbindkey_wrapper debug: key = b:12

min_keycode=8     max_keycode=255 (ie: know keycodes)
"(Scheme function)"
    m:0x0 + b:8   (mouse)
"(Scheme function)"
    m:0x0 + b:9   (mouse)
"(Scheme function)"
    m:0x0 + b:10   (mouse)
"(Scheme function)"
    m:0x0 + b:11   (mouse)
"(Scheme function)"
    m:0x0 + b:12   (mouse)
^C
As you can see, in this version, my function with the debug output gets called; in the end, the buttons get new bindings.

What strikes me as the main difference is this

Code:
Button press !
e.xbutton.button=8
e.xbutton.state=16
[...]
Button release !
e.xbutton.button=8
e.xbutton.state=8208
(broken) vs this

Code:
Button press !
e.xbutton.button=8
e.xbutton.state=0
[...]
Button release !
e.xbutton.button=8
e.xbutton.state=0
(working). Unfortunately, I could not find out anything about the meaning of e.xbutton.state. Can anyone shed some light on the subject?
 
  


Reply

Tags
xbindkeys


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mouse keys as modifier keys (ctrl & alt) belda Linux - Desktop 3 06-25-2009 10:37 AM
about xwindow. mouse left button and right button chuangsheng Programming 4 06-13-2009 12:34 AM
how should i enable the middle button of 3-button mouse ?? b0nd Slackware 1 07-17-2006 02:46 AM
3 button mouse (scroll button) Spyiish Slackware 24 07-23-2005 01:37 PM
middle mouse button is paste.. but what if i dont have a mid mouse button? kublador Linux - Newbie 4 09-02-2003 08:59 AM


All times are GMT -5. The time now is 11:42 AM.

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
Open Source Consulting | Domain Registration