xbindkeys: Mouse button as modifier (second attempt)
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
xbindkeys: Mouse button as modifier (second attempt)
Hi!
A while ago, I asked about using mouse buttons as modifiers through an .xbindkeysrc.scm file. Unfortunately, it seems xbindkeys is a bit buggy, and won't allow me to switch between levels of mouse bindings when a button is held.
Now, I'd like to try a simpler approach: The mouse button would simply have to act as if a modifier on the keyboard was pressed and held for as long as the button is down.
How would I be able to accomplish this? It seemed simple, binding 'xdotool keydown ctrl' to b:8 and 'xdotool keyup ctrl' to b:8 + Release (or control + b:8 + release, as ctrl should be recognized as pressed when I release), but this just doesn't do it and the behavior is very strange any way I tried.
So, I'd need a way to make this work. Is there a way to directly modify the OS's keyboard buffer, so an exactly identical state to a button beind pressed, held and release can be emulated, without the help of additional tools? Or is there a program fashioned exactly to suit this purpose, to toggle the state of modifiers? Or is there a tool similar to xbindkeys which I could try?
// Send a fake keystroke event to an X window.
// by Adam Pierce - http://www.doctort.org/adam/
// modified by veek in order to generate keystrokes that aren't marked "synthetic,"
// so the receiving application thinks it's receiving genuine keyboard input.
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include <stdio.h>
#include <string.h>
// The key code to be sent.
// A full list of available codes can be found in /usr/include/X11/keysymdef.h
#define KEYCODE XK_F7
#define KEYCODE1 XK_Alt_L
#define KEYCODE2 XK_Left
#define KEYCODE3 XK_Control_L
#define KEYPRESS 1
#define KEYRELEASE 0
main()
{
// Obtain the X11 display.
Display *display = XOpenDisplay(0);
if(display == NULL) {
printf("Display not found\n");
return -1;
}
// Get the root window for the current display.
Window winRoot = XDefaultRootWindow(display);
// Find the window which has the current keyboard focus.
Window winFocus;
int revert;
XGetInputFocus(display, &winFocus, &revert);
// Send ALT + LEFT key sequence to currently targeted window
XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE1), KEYPRESS, 0);
XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE3), KEYPRESS, 0);
XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE2), KEYPRESS, 0);
XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE2), KEYRELEASE, 0);
XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE3), KEYRELEASE, 0);
XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE1), KEYRELEASE, 0);
// Done.
XCloseDisplay(display);
return 0;
}
This might help in some way, but it only works for the app that has focus. How can I trick the X server itself?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.