LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 10-15-2011, 03:17 PM   #1
Vinter
Member
 
Registered: Feb 2005
Location: Germany
Distribution: Aptosid
Posts: 148

Rep: Reputation: 19
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?

Thanks for any help!

Vinter
 
Old 10-17-2011, 05:18 AM   #2
Vinter
Member
 
Registered: Feb 2005
Location: Germany
Distribution: Aptosid
Posts: 148

Original Poster
Rep: Reputation: 19
I found this:

Code:
// 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?
 
  


Reply



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
[xbindkeys] Mouse button as modifier Vinter Linux - Software 6 09-20-2012 10:24 PM
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:29 PM.

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