It is currently Sat May 25, 2013 11:17 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Global shortcut
PostPosted: Wed Feb 08, 2012 7:33 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 278
Location: Germany
I use a globale shortcut for my program. (ALT-C)
Have any where a sample?

Thanks
Michael

_________________
Sorry, My english is not so good


Top
 Profile  
 
 Post subject: Re: Global shortcut
PostPosted: Wed Feb 08, 2012 12:39 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 22, 2003 2:51 am
Posts: 734
Location: Canada
Hi,

To add a Shortcut inside a program you will have to do this :

Code:
AddKeyboardShortcut(#Your_window, #PB_Shortcut_ALT | #PB_ShortCut_C, #Related_Menu_Event_ID)


Best regards.
Guimauve


Top
 Profile  
 
 Post subject: Re: Global shortcut
PostPosted: Wed Feb 08, 2012 1:28 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 278
Location: Germany
It´s only for active application...

_________________
Sorry, My english is not so good


Top
 Profile  
 
 Post subject: Re: Global shortcut
PostPosted: Wed Feb 08, 2012 8:03 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 22, 2003 2:51 am
Posts: 734
Location: Canada
What do you mean ?

You would like to use a Global shortcut to call another program ?

Best regards.
Guimauve


Top
 Profile  
 
 Post subject: Re: Global shortcut
PostPosted: Wed Feb 08, 2012 8:24 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4715
Location: Berlin - Germany
A hotkey that works on the system like
Code:
RegisterHotKey_(WindowID(Window), HotkeyID, fsModifiers, Keys)
in windows.
http://msdn.microsoft.com/en-us/library ... 85%29.aspx

_________________
PureBasic 5.11 | Windows 7 SP1 (x64) | Mageia 3 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
 Post subject: Re: Global shortcut
PostPosted: Wed Feb 08, 2012 10:34 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Dec 20, 2003 6:19 pm
Posts: 467
Location: Switzerland
You can find an example in C for a global hotkey here:
http://lists.freedesktop.org/archives/x ... 51567.html

_________________
Athlon64 3700+, 1024MB Ram, Radeon X1600


Top
 Profile  
 
 Post subject: Re: Global shortcut
PostPosted: Thu Feb 09, 2012 5:25 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 814
Location: Germany
Thank you Remi for your link. My first own Google searches only found global hotkey examples
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:
; Converted from cheshirekow's C-Code:
; http://lists.freedesktop.org/archives/xorg/2010-October/051567.html

EnableExplicit

#ControlMask = 1 << 2
#GrabModeAsync = 1
#KeyPress = 2
#KeyPressMask = 1
#ShiftMask = 1
#XK_K = $004B

ImportC "/usr/lib/i386-linux-gnu/libX11.a"
; ImportC "/usr/lib/libX11.a"
  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 "/usr/lib/i386-linux-gnu/libxcb.a" : EndImport
; ImportC "/usr/lib/libxcb.a" : EndImport
ImportC "/usr/lib/i386-linux-gnu/libXau.a" : EndImport
; ImportC "/usr/lib/libXau.a" : EndImport
ImportC "/usr/lib/i386-linux-gnu/libXdmcp.a" : EndImport
; ImportC "/usr/lib/libXdmcp.a" : 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

      Delay(20)
    ForEver

    XCloseDisplay(*Display)
  EndIf
EndIf


Top
 Profile  
 
 Post subject: Re: Global shortcut
PostPosted: Fri Feb 10, 2012 8:29 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 278
Location: Germany
Thanks to all

GT :wink:

_________________
Sorry, My english is not so good


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye