[Gambas-user] How to show a form with keyboard shortcut

Doriano Blengino doriano.blengino at ...1909...
Mon Aug 17 22:44:07 CEST 2009


HARADA Kazutaka ha scritto:
> Sorry fo late reply,
>
>   
>> You can't if you don't have the focus. What you need is a global shortcut, 
>> which is managed by your desktop environment, or a special program. 
>>
>> For example, in KDE, there is a control panel entry for configuring them.
>>   
>>     
>
> Yes, you are right.
> But I'm looking for a window manager (or desktop environment) 
> independent way.
>
> So I start to write a test program using Xlib with EXTERN declaration 
> like this.
>
> ' Gambas module file
> EXTERN XOpenDisplay(DpyName AS String) AS Pointer IN "libX11"
> EXTERN XDefaultScreen(Display AS Pointer) AS Integer IN "libX11"
> EXTERN XDefaultRootWindow(Display AS Pointer) AS Integer IN "libX11"
> EXTERN XSelectInput(Display AS Pointer, Window AS Integer, KeyMask AS 
> Long) IN "libX11"
> EXTERN XNextEvent(Display AS Pointer, XEvent AS Pointer) IN "libX11"
> EXTERN XGrabKey(Display AS Pointer, KeyCode AS Integer, Modifiers AS 
> Integer, Window AS Pointer, OwnEvent AS Boolean, PointerMode AS Integer, 
> KeyboardMode AS Integer) IN "libX11"
>
> PUBLIC SUB Main()
>
>     DIM pDisplay AS Pointer
>     DIM pRootWindow AS Pointer
>     DIM pEvent AS Pointer
>
>     pDisplay = XOpenDisplay("")
>     pRootWindow = XDefaultRootWindow(pDisplay)
>     XSelectInput(pDisplay, pRootWindow, 1)              '1 = KeyPressMask
>     XGrabKey(pDisplay, 95, 0, pRootWindow, FALSE, 1, 1) '95 = F11 key, 
> 1=GrabModeAsync
>     DO
>         XNextEvent(pDisplay, pEvent)
>         PRINT ("Key F11 Pressed")
>     LOOP
> END
>
> When F11 Key, keycode is 95 on my japanese keyboard, is pressed,
> It should print the message. But actually program exit with signal 11.
>
> Any comments or suggestions are wlecome.
>   
Hi,

I think that in the call to XNextEvent you are passing a NIL pointer; 
libX11 tries to put data in the area pointed by pEvent. You should 
allocate some memory in it, enough to hold the event data. If, on the 
other hand (I don't have the docs at hands right now), X11 should 
allocate the event, and return to you the pointer to the event, then 
again you should pass to X11 a pointer to a pointer... but you pass it a 
NULL.

Anyway, my compliments for the low-level management. This is not seen 
every day :-)

Regards,
Doriano





More information about the User mailing list