Page 1 of 1

Posted: Fri Oct 04, 2002 1:18 am
by BackupUser
Restored from previous forum. Originally posted by Jose.

Hi All,

Anyone know how to within a PB app, detect when a window Shortcut keys is pressed, these are usualy CTRL+ALT+.

I know that you can use AddKeyboardShortcut() to do this in Pb App, but this only works when app has focus, I want to detect the keys like windows detects desktop shortcuts hotkeys.

Yes, it's windows specific so API will do...:)

Any help, code would be appreciated.
Thanks
Jose

Registered PureBasic User, 2.60-)

Posted: Fri Oct 04, 2002 1:48 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> Anyone know how to within a PB app, detect when a window Shortcut
> keys is pressed, these are usualy CTRL+ALT+.
> it's windows specific so API will do...:)

There is probably a better and cleaner way to do it, but try this:

Code: Select all

; Clear key buffers before use.
GetAsyncKeyState_(#VK_CONTROL)
GetAsyncKeyState_(#VK_SHIFT)
GetAsyncKeyState_(#VK_H)
;
If OpenWindow(0,200,200,450,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  ButtonGadget(0,50,50,100,21,"Press Shift+Ctrl+H")
  Repeat
    Sleep_(1) : ev=WindowEvent() ; Don't use WaitWindowEvent or we won't see the keypress.
    If GetAsyncKeyState_(#VK_H)=-32767 And GetAsyncKeyState_(#VK_CONTROL)=-32767 And GetAsyncKeyState_(#VK_SHIFT)=-32767
      MessageBeep_(#MB_ICONASTERISK)
    EndIf
  Until ev=#PB_EventCloseWindow
EndIf
> Registered PureBasic User, 2.60-)

Still using v2.60 -- why not upgrade to v3.30?


PB - Registered PureBasic Coder

Posted: Fri Oct 04, 2002 9:05 am
by BackupUser
Restored from previous forum. Originally posted by Jose.

Wow PB, that works, many Thanks for the fast reply.

One question how do I make it work with the CTRL+ALT+SomeKey combination instead of CTRL+SHIFT, I treid VK_ALT instead of VK_SHIFT but it's not defined.
Any ideas.

> Registered PureBasic User, 2.60-)
Oh, it's misleading, it requires translation... Registered since 2.60 and using the latest version all the time, will fix...

Thanks again
Jose


Registered PureBasic User, 2.60-)

Posted: Fri Oct 04, 2002 10:52 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> how do I make it work with the CTRL+ALT+SomeKey combination instead
> of CTRL+SHIFT, I treid VK_ALT instead of VK_SHIFT but it's not defined.

ALT is actually called MENU, so use VK_MENU instead of VK_ALT.
It's just a strange Windows thing. :) See here for a listing:

http://216.26.168.92/vbapi/ref/other/vi ... codes.html


PB - Registered PureBasic Coder

Posted: Fri Oct 04, 2002 5:39 pm
by BackupUser
Restored from previous forum. Originally posted by Jose.

Thanks Again PB, thats exactly what I needed
Jose

Registered PureBasic User