![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 5
| global kbd hook |
| ArtemS2006 is offline | |
| | #2 |
| Registered User Join Date: Oct 2009
Posts: 5
| here's sample code i found so far but unfortunately it doesn't work on keys that were hooked by other apps. Code: #include <X11/Xlib.h> // Every Xlib program must include this
#include <assert.h> // I include this to test return values the lazy way
#include <unistd.h> // So we got the profile for 10 seconds
#include <iostream>
#define NIL (0) // A name for the void pointer
main()
{
// Open the display
Display *dpy = XOpenDisplay(NIL);
assert(dpy);
// Get some colors
int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
// Create the window
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
200, 100, 0, whiteColor, whiteColor);
// Grab F2 key with code 68 (experiment by yourself)
int F2_KEY = 68;
XGrabKey( dpy, F2_KEY, AnyModifier, w, true, GrabModeAsync, GrabModeAsync );
// "Map" the window (that is, make it appear on the screen)
XMapWindow(dpy, w);
// Infinite loop ( hazard thing ;) )
for(;;) {
XEvent e;
XNextEvent(dpy, &e);
if (e.type == KeyPress )
{
printf( "F2 was pressed!!!\n" );
}
}
}
|
| ArtemS2006 is offline | |
| | #3 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| So basically you are looking to screw up the system and/or other applications? No one wants software like that and no one will help you create it.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #4 |
| Registered User Join Date: Oct 2009
Posts: 5
| What made you think i'm going to make destructive app? i've got a task of prohibiting screenshot in linux. The task consists of 2 things: - Show a message "screecshot cannot be done when app is launched", when user pushes PrintScreen. - Make app's window to be unscreenshotable (i asked about it in another topic prohibit screenshots). By the way, this all is not my idea, i'm just doing the job. |
| ArtemS2006 is offline | |
| | #5 |
| Jaxom's & Imriel's Dad Join Date: Aug 2006 Location: Alabama
Posts: 801
| Let me confuse this issue for you a bit more -- Shall we? Which environment are you planning to do this in? How will you stop the user from executing this from the command line? Bottom line: you cannot achieve what you want unless you really protect yourself by limiting yourself to ONE specific environment. Now, which one will that be? The problem is not as easy as "binding the keyboard up so that no one can do printscreen" as the keyboard is NOT the only way that this could be done. Furthermore, who is to say that I don't have CTRL-BREAK as the defined way to get a screen shot? What if I'm in KDE and you've written this for gnome? Without seriously mucking around with others' machines, you cannot do this. |
| Kennedy is offline | |
| | #6 | |
| Registered User Join Date: Oct 2009
Posts: 5
| Quote:
| |
| ArtemS2006 is offline | |
| | #7 |
| Jaxom's & Imriel's Dad Join Date: Aug 2006 Location: Alabama
Posts: 801
| Examples of an environment are KDE, gnome, xf86, etc, etc. There are about a dozen or so of these. So, you are not using any environment at all? Your app is to be run as the environment? |
| Kennedy is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ Global Keyboard Hook | darknite135 | C++ Programming | 4 | 02-01-2008 07:36 PM |
| blocking or passing keys with global hook | pmouse | Windows Programming | 4 | 08-29-2007 02:54 PM |
| Problems with global hook! HELP! | LMZ | Windows Programming | 3 | 08-22-2006 08:09 AM |
| Global hook only works on one window? | CornedBee | Windows Programming | 5 | 01-19-2004 12:25 PM |