Re: map 2nd 3rd mouse buttons?
Attached is a quick hack for X, that allows you to hold a key down
( option key in my case ) and click the mouse for a right click, double
tap and hold the key, then click mouse for a middle click.
You may need to change the value 115 in the source for your keyboard -
find keycode with xev.
Probably not a good idea to release the key before the mouse button.
Worked more natural for me than reaching up for function keys.
-- mallum
on Tue, Mar 26, 2002 at 07:51:23PM -0500, B.C.J.O wrote:
> On Tue, 19 Mar 2002, ragnar wrote:
>
> > I'm using a powerbook 3400c which of course has a one button touch pad.
> > Does anyone know how to map mouse events generated by a middle and right
> > button click of a typical 3-button mouse to either a keyboard key or
> > combo of key and mouse click?
>
> This was one of my first questions after migrating my lombard to debian..
> the solution is painless. Add the following lines to /etc/sysctl.conf
>
> dev.mac_hid.mouse_button2_keycode = 87
> dev.mac_hid.mouse_button3_keycode = 88
> dev.mac_hid.mouse_button_emulation = 1
>
> which binds the middle and right mouse buttons to f11 and f12
> respectively, after you run 'sysctl -p' which will apply the new lines
> from sysctl.conf
>
> If you don't like f11 and f12, you'll have to look up the keycodes for the
> other keys. =)
>
> Brian
> fade@etc.etc.etc.
>
> "You can't depend on your judgement when your imagination
> is out of focus." -- Mark Twain
>
>
> --
> To UNSUBSCRIBE, email to debian-powerpc-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
/* XMonobut - Modify mouse button behaviour with keyboard.
o Usage
Hold selected key ( KEYSYM_TO_GRAB ) down and click mouse button for
right click.
Quickly press selected key once, then again holding down for middle click.
o Compiling
gcc -Wall XMonobut.c -o xmonobut -L/usr/X11R6/lib -lX11
Copyright 2002 Matthew Allum <mallum@handhelds.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xmd.h>
#include <X11/keysym.h>
#include <X11/cursorfont.h>
#define KEYSYM_TO_GRAB 115 /* get from xev or keysym.h */
#define DCLICK_TIME 200
int main(int argc, char **argv)
{
Display *dpy;
char *dpy_name = NULL;
Window root;
XEvent ev;
Cursor right_curs, middle_curs, orig_curs;
Time lasttime = 0;
unsigned char map[5];
if ((dpy = XOpenDisplay(dpy_name)) == NULL) {
fprintf(stderr, "can't open display! check your DISPLAY variable.\n");
exit(1);
}
root = RootWindow(dpy, DefaultScreen(dpy));
/* see http://tronche.com/gui/x/xlib/appendix/b/ for more cursors */
right_curs = XCreateFontCursor(dpy, XC_mouse);
middle_curs = XCreateFontCursor(dpy, XC_gumby); /* :) */
orig_curs = XCreateFontCursor(dpy, XC_left_ptr);
XGrabKey(dpy, 115, 0 /*XKeysymToKeycode(dpy, KEYSYM_TO_GRAB), AnyModifier*/ ,
root, True, GrabModeAsync, GrabModeAsync);
XSelectInput(dpy, root, KeyPressMask | KeyReleaseMask );
for (;;) {
XNextEvent(dpy, &ev);
switch (ev.type) {
case KeyPress:
if (ev.xkey.keycode != 115) break;
XAutoRepeatOff(dpy);
XGetPointerMapping(dpy, map, 5);
if (lasttime && (ev.xkey.time-lasttime < DCLICK_TIME) )
{ /* double press - remap for middle button */
map[0] = (unsigned char) 2;
map[1] = (unsigned char) 3;
map[2] = (unsigned char) 1;
XDefineCursor(dpy, root, middle_curs);
} else {
map[0] = (unsigned char) 3;
map[1] = (unsigned char) 2;
map[2] = (unsigned char) 1;
XDefineCursor(dpy, root, right_curs);
}
lasttime = ev.xkey.time;
XSetPointerMapping(dpy, map, 5);
break;
case KeyRelease:
if (ev.xkey.keycode != 115) break;
/* Put everything back to normal */
map[0] = (unsigned char) 1;
map[1] = (unsigned char) 2;
map[2] = (unsigned char) 3;
XSetPointerMapping(dpy, map, 5);
XDefineCursor(dpy, root, orig_curs);
XAutoRepeatOn(dpy);
break;
}
}
XUngrabKey(dpy, 115 /* XKeysymToKeycode(dpy, KEYSYM_TO_GRAB) */, AnyModifier, root);
XCloseDisplay(dpy);
}
Reply to: