It is currently Wed Jan 27, 2021 6:57 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Shortcut keys in windows programs
PostPosted: Fri Aug 21, 2020 5:36 pm 
Offline
New User
New User

Joined: Fri Jan 17, 2020 8:20 pm
Posts: 4
Hello!
Is it possible to capture keystrokes outside the window?
There is a library (autoitx3), which seems to do this. But it works only on purebasic 4.00.
I am studying the library "MSAA" (Microsoft active accessibility), which seems to facilitate this feature in current versions of purebasic. But my original language is Brazilian Portuguese. The google translator helps, but very slow. And in fact, I don't even know how to use PureBasic correctly.
Does anyone know how to do this?
Thank you in advance.

Original em português.

Olá!
É possível capturar pressionamento de teclas fora da janela?
Há uma biblioteca (autoitx3), que parece fazer isso. Mas funciona apenas no purebasic 4.00.
Estou estudando a biblioteca "MSAA" (Microsoft active accessibility), que parece facilitar esse recurso nas versões atuais do purebasic. Mas meu idioma original é português brasileiro. O google tradutor ajuda, porém muito lento. E na verdade, nem sei como usar com o PureBasic corretamente.
Alguém sabe como fazer isso?
Grato desde já.


Top
 Profile  
Reply with quote  
 Post subject: Re: Shortcut keys in windows programs
PostPosted: Sat Aug 22, 2020 9:22 pm 
Offline
New User
New User

Joined: Fri Jan 17, 2020 8:20 pm
Posts: 4
I found something very simple.
Although I still don't understand how it works, but it serves what I need.
The source was at: http://forums.purebasic.com/english/vie ... 13&t=29773

Code:

; use: (Ctrl+a), (F7), and (escape to quit) in any window.
Procedure SetHotKey(*hWnd,Key,Modifiers)
   Static ID
   ID+1
   If RegisterHotKey_(*hWnd,ID,Modifiers,Key)=0
     ProcedureReturn -1
   EndIf
   ProcedureReturn ID
EndProcedure

Procedure HotKeyMsg()
   msg.MSG
   GetMessage_(@msg,0,0,0)
   If msg\message=#WM_HOTKEY
      ProcedureReturn msg\wParam
   EndIf
EndProcedure

OpenWindow(0,0,0,0,0,"",#PB_Window_Invisible)

   *hwnd=GetForegroundWindow_()

   hk_ctrla=SetHotKey(WindowID(0),#VK_A,#MOD_CONTROL)
   hk_f7=SetHotKey(WindowID(0),#VK_F7,0)
   hk_esc=SetHotKey(WindowID(0),#VK_ESCAPE,0)
   
  Repeat
     HotKeyEvent=HotKeyMsg()
     If HotKeyEvent
        Select HotKeyEvent
           Case hk_ctrla
             ;PrintN("Ctrl-A")
             MessageBeep_(64)
             
           Case hk_f7
             MessageRequester("Hey!", "The F7 key was pressed!", 64)
             
           Case hk_esc
             Break
        EndSelect

     EndIf

     Delay(20) ; Don't eat all the CPU time, we're on a multitask OS
   ForEver
   
MessageRequester("Notify", "Bye!", 64)
;EndIf



Sorry if the code got ugly after I modified it, but I'm blind, and the structure makes no difference to my ears.


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


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