which are bound to the desktop manager. So I thought the only way to realize a solution would
have been to write separate routines for the desktop managers KDE 3 + 4, Gnome 2 + 3 + Unity,
Xfce, LXDE...
But since all distributions are currently still using XWindow (until some of them will change to
Wayland) using XWindow API functions should be the most practical approach. Therefore I tried
to convert the posted C code to PB. Currently I have tested this code to detect the newly
established hotkey <Ctrl> + <Shift> + <K> successfully in Ubuntu 11.10, Kubuntu 11.10 and Linux
Mint 12. For non-Ubuntu based distributions (or pre 11.04 Ubuntu distributions) the path to the
Xlibs has to be changed!
Code: Select all
; Converted from cheshirekow's C-Code:
; http://lists.freedesktop.org/archives/xorg/2010-October/051373.html
EnableExplicit
#ControlMask = 1 << 2
#GrabModeAsync = 1
#KeyPress = 2
#KeyPressMask = 1
#ShiftMask = 1
#XK_K = $004B
ImportC "-lX11"
XCloseDisplay(*Display)
XDefaultRootWindow(*Display)
XGrabKey(*Display, KeyCode.I, Modifiers.I, GrabWindow.I, OwnerEvents.i, PointerMode.I, KeyboardMode.I)
XKeysymToKeycode(*Display, KeySym.I)
XNextEvent(*Display, *XEvent)
XOpenDisplay(*Display)
XSelectInput(*Display, Window.I, EventMask.I)
XUngrabKey(*Display, KeyCode.I, Modifiers.I, GrabWindow.I)
EndImport
ImportC "-lxcb" : EndImport
ImportC "-lXau" : EndImport
ImportC "-lXdmcp" : EndImport
Structure XEvent
EventType.I
SendEvent.I
*Display
EventWindow.I
RootWindow.I
ChildWindow.I
Time.I
x.I
y.I
x_root.I
y_root.I
Mask.I
KeyCode.I
SameScreen.I
EndStructure
Define *Display
Define Event.XEvent
Define KeyCode.I
Define RootWindow.I
*Display = XOpenDisplay(0)
If *Display
RootWindow = XDefaultRootWindow(*Display)
If RootWindow
KeyCode = XKeysymToKeycode(*Display, #XK_K)
XGrabKey(*Display, KeyCode, #ControlMask | #ShiftMask, RootWindow, #False, #GrabModeAsync, #GrabModeAsync)
XSelectInput(*Display, RootWindow, #KeyPressMask)
Repeat
XNextEvent(*Display, @Event)
If Event\EventType = #KeyPress
MessageRequester("Info", "Global Hotkey <Ctrl> + <Shift> + <K> detected and removed!")
XUngrabKey(*Display, KeyCode, #ControlMask | #ShiftMask, RootWindow)
Break
EndIf
ForEver
XCloseDisplay(*Display)
EndIf
EndIf
Furthermore I had to modify the link to the C source code of the original author.