|
|
(4 versioni intermedie di uno stesso utente non sono mostrate) |
Riga 1: |
Riga 1: |
− | Con alcune risorse della libreria di '''X11''' è possibile, premendo una combinazione di tasti della tastiera, uscire da un'applicazione.
| + | #REDIRECT [[Uscire da un'applicazione Gambas premendo un tasto mediante le funzioni del API di X11]] |
− | | |
− | E' necessario richiamare nell'applicazione Gmambas la libreria dinamica condivisa del sistem X11: "''libX11.so.6.3.0''"
| |
− | | |
− | | |
− | Mostriamo un semplice esempio pratico, nel quale, premendo la combinazione dei tasti ''Ctrl'', ''shift'' e "''q''", si determinerà la chiusura dell'applicazione:
| |
− | 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)
| |
− | Private ControlMask As Integer = 1 * CInt(2 ^ 2)
| |
− | Private ShiftMask As Integer = 1 * CInt(2 ^ 0)
| |
− |
| |
− | <FONT Color=gray>' ''Display *XOpenDisplay(char *display_name)''
| |
− | ' ''Opens a connection to the X server that controls a display.''</font>
| |
− | Private Extern XOpenDisplay(display_name As Pointer) As Pointer
| |
− |
| |
− | <FONT Color=gray>' ''Window XDefaultRootWindow(Display *display)''
| |
− | ' ''Returns the root window for the default screen.''</font>
| |
− | Private Extern XDefaultRootWindow(display As Pointer) As Integer
| |
− |
| |
− | <FONT Color=gray>' ''KeyCode XKeysymToKeycode(Display *display, KeySym keysym)''
| |
− | ' ''Obtains a KeyCode for a key having a specific KeySym.''</font>
| |
− | Private Extern XKeysymToKeycode(display As Pointer, keysym As Integer) As Integer
| |
− |
| |
− | <FONT Color=gray>' ''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.''</font>
| |
− | 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)
| |
− |
| |
− | <FONT Color=gray>' ''XSelectInput(Display *display, Window w, long event_mask)''
| |
− | ' ''Requests that the X server report the events associated with the specified event mask.''</font>
| |
− | Private Extern XSelectInput(display As Pointer, w As Integer, event_mask As Long)
| |
− |
| |
− | <FONT Color=gray>' ''XNextEvent(Display *display, XEvent *event_return)''
| |
− | ' ''Gets the next event and remove it from the queue.''</font>
| |
− | Private Extern XNextEvent(display As Pointer, event_return As Pointer)
| |
− |
| |
− | <FONT Color=gray>' ''XUngrabKey(Display *display, int keycode, unsigned int modifiers, Window grab_window)''
| |
− | ' ''Ungrabs a key.''</font>
| |
− | Private Extern XUngrabKey(display As Pointer, keycode As Integer, modifiers As Integer, Window As Pointer)
| |
− |
| |
− | <FONT Color=gray>' ''XCloseDisplay(Display *display)''
| |
− | ' ''Closes a display or disconnects from the X server.''</font>
| |
− | 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
| |
− | Dim esce As Boolean
| |
− |
| |
− | ev = Alloc(192)
| |
− |
| |
− | dpy = XOpenDisplay(0)
| |
− |
| |
− | root = XDefaultRootWindow(dpy)
| |
− |
| |
− | keycode = XKeysymToKeycode(dpy, Asc("q"))
| |
− |
| |
− | 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 "Premuto il tasto 'q' !"
| |
− | XUngrabKey(dpy, keycode, ControlMask Or ShiftMask, root)
| |
− | esce = True
| |
− | Case Else
| |
− | Break
| |
− | End Select
| |
− | If esce Then Break
| |
− | Wend
| |
− |
| |
− | Free(ev)
| |
− | XCloseDisplay(dpy)
| |
− |
| |
− | '''End'''
| |
− | | |
− | | |
− | | |
− | | |
− | =Riferimenti=
| |
− | * https://tronche.com/gui/x/
| |
− | * http://www.x.org/archive/X11R7.5/doc/libX11/libX11.html
| |