Link to home
Start Free TrialLog in
Avatar of KiCk
KiCk

asked on

Linux/X11 Keyboard interceptor

Hi,

for some twisted reason, i need to write a program that locks any input from keyboard/mouse for other than my application.
I already tried, with limited success, with SDL WM_GrabInput, but that does not grab key combinations like CTRL+ALT+BACKSPACE or CTRL+ALT+F2.

What i need is advice, and possibly C (im programming in FPC for this) code to accomplish a total lockout from the keyboard, in order to prevent X shutdown, or console switching.
I dont expect answers or comments like "use XDM" or "disable the TTYs and run in X runlevel", since that's not what im looking for (actually might be the worst case scenario if there's no other solution to my problem".

Thanks.
Avatar of Alf666
Alf666

Get the source of the "xev" utility.

It's a small X11 utility that allows you to grab any X11 events (including key presses/releases).
It's a very old X11 stuff which is a perfect example of what you are trying to achieve. It uses native X11 calls.
To prevent the Xserver from ending / switching to VTs on CTRL+ALT+BACKSPACE / CTRL+ALT+F2, you need to change you XF86Config. Activate options DontZoom and DontZap.
Avatar of KiCk

ASKER

DontZap does not prevent console switching.
DontZoom prevents the user from switching screen resolution, which i actually need :)

As for xev, that captures the events from within the window, not from all windows.
ASKER CERTIFIED SOLUTION
Avatar of astrand
astrand

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I know the xev does not get all events, but it's a good example of what can be done.
Based on that, you can do whatever you want.