Sì, giusto. Bravo.
Bene, ora il codice in C++ funziona.
Intanto ho rivisto anche il codice in Gambas: ho semplicemente tradotto quel codice funzionante dal C++ in Gambas; e funziona anche questo:
Library "libX11:6.3.0"
Private Enum KeyPress = 2, KeyRelease, ButtonPress, ButtonRelease, MotionNotify, EnterNotify, LeaveNotify,
FocusIn, FocusOut, KeymapNotify, Expose, GraphicsExpose, NoExpose
Private Const GrabModeAsync As Integer = 1
Private KeyPressMask As Integer = 1 * CInt(2 ^ 0) ' 1L<<0 '
Private ControlMask As Integer = 1 * CInt(2 ^ 2) ' 1<<2 '
Private ShiftMask As Integer = 1 * CInt(2 ^ 0) ' 1<<0 '
' Display *XOpenDisplay(char *display_name)'
' Opens a connection to the X server that controls a display.'
Private Extern XOpenDisplay(display_name As Pointer) As Pointer
' Window XDefaultRootWindow(Display *display)'
' Returns the root window for the default screen.'
Private Extern XDefaultRootWindow(display As Pointer) As Integer
' KeyCode XKeysymToKeycode(Display *display, KeySym keysym)'
' Obtains a KeyCode for a key having a specific KeySym.'
Private Extern XKeysymToKeycode(display As Pointer, keysym As Integer) As Integer
' XGrabKey(Display *display, int keycode, unsigned int modifiers, Window grab_window, Bool owner_events, int pointer_mode, int keyboard_mode)'
' Passively grabs a single key of the keyboard.'
Private Extern XGrabKey(display As Pointer, keycode As Integer, modifiers As Integer, grab_window As Integer, owner_events As Boolean, pointermode As Integer, keyboard_mode As Integer)
' XSelectInput(Display *display, Window w, long event_mask)'
' Requests that the X server report the events associated with the specified event mask.'
Private Extern XSelectInput(display As Pointer, w As Integer, event_mask As Long)
' XNextEvent(Display *display, XEvent *event_return)'
' Gets the next event and remove it from the queue.'
Private Extern XNextEvent(display As Pointer, event_return As Pointer)
' XUngrabKey(Display *display, int keycode, unsigned int modifiers, Window grab_window)'
' Ungrabs a key.'
Private Extern XUngrabKey(display As Pointer, keycode As Integer, modifiers As Integer, Window As Pointer)
' XCloseDisplay(Display *display)'
' Closes a display or disconnects from the X server.'
Private Extern XCloseDisplay(display As Pointer)
Public Sub Main()
Dim dpy As Pointer
Dim root As Integer
Dim ev As Pointer
Dim keycode As Integer
ev = Alloc(192)
dpy = XOpenDisplay(0)
root = XDefaultRootWindow(dpy)
keycode = XKeysymToKeycode(dpy, Asc("y"))
XGrabKey(dpy, keycode, ControlMask Or ShiftMask, root, False, GrabModeAsync, GrabModeAsync)
XSelectInput(dpy, root, KeyPressMask)
While True
XNextEvent(dpy, ev)
Select Case Int@(ev)
Case KeyPress
Print "Hot key pressed !"
XUngrabKey(dpy, keycode, ControlMask Or ShiftMask, root)
Break
End Select
Wend
Free(ev)
XCloseDisplay(dpy)
End