Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Nov 12, 2018 9:43 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Register hotkey?
PostPosted: Mon Mar 12, 2012 10:04 am 
Offline

Joined: Sat Jul 16, 2011 2:45 pm
Posts: 76
Hi all,

I'm making an application that will respond to key presses while another application is running (will play a sound and then another sound after a timer)

I've been directed towards window's "register hotkey" API as the means of doing it correctly.

I've been able to "register" my hotkeys i.e. F1-F6, which appears to be working fine /done correctly but I am a bit lost as to how one "responds" to them after?

supposedly it is thrown into the top of the message queue for that window /process and you have to get it but I am not sure how to do this correctly, as I'm assuming RS is reading the message queue itself aswell? and microsoft API pages are just a sad sight to read and try understand half the time.


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Mon Mar 26, 2012 6:31 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Have you looked at the HotKeyHelper class in the Windows Functionality Suite (included in the examples directory)?

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Thu Mar 29, 2012 10:33 am 
Offline

Joined: Sat Jul 16, 2011 2:45 pm
Posts: 76
Thanks for the reply

I found "Windows Functionality Suite" and downloaded it, I've also looked at the HotKeyHelper class it has, but I don't see any examples?

Looking at the class I can see it is what I need, but am not quite sure how I am supposed to be using it? I can register a hot key with fine, but what am I supposed to be doing from there?? :S


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Thu Mar 29, 2012 12:32 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
lukus001 wrote:
Looking at the class I can see it is what I need, but am not quite sure how I am supposed to be using it

That's pretty much the definition of the Windows Functionality Suite :lol: (in my experience.)

When you register a hotkey with the RegisterHotKey function it returns an Integer which uniquely identifies the key combo (the "identifier"). This identifier is then passed to the HotKeyReceived event where you handle each hotkey you registered. You detect which hotkey was pressed by looking at the identifier and acting accordingly:

Function HotKeyPressed(identifier as Integer, keyString as String) As Boolean
If identifier = myHotKeyID Then //Assume that myHotKeyID is the identifier you got from RegisterHotKey
MsgBox("Hotkey pressed!")
Return True //Return true to indicate that you handled the hotkey, or false to indicate that you haven't
End If
End Function


In the above example all we do is show a MsgBox whenever the hotkey combo is pressed, but you can do pretty much anything here.

So basically: store the Integer that you get from RegisterHotKey and then compare it to the identifier you get in the HotKeyReceived event (if you only registered one hotkey you can probably get away without checking the identifier, but you should still save the identifier so you can pass it to UnregisterHotKey when/if you need to unregister it later.)

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Thu Mar 29, 2012 1:56 pm 
Offline

Joined: Sat Jul 16, 2011 2:45 pm
Posts: 76
Thank you once again.

So do I not have to call /use Wndproc in anyway?

This is what has made me confused as to how to properly use 'register hokey', as I was under the assumption as part of creating a "window", one has to fetch messages from the message queue (which I assume real studio is doing to an extent with it's framework for most messages to be cross platform), but WM_HOTKEY messages are sent on this same queue?

Do i just register my hotkeys with registerhotkey and then put my code in the hotkeypressed event? does the wndproc method in the class go unused ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Thu Mar 29, 2012 2:45 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Aaron's code usually handles wndProc for you under the hood. He uses the typical window subclassing scheme (in Win32 terms) where you create your own wndProc, save the original wndProc and replace it with your own. You then handle the messages you care about and forward everything else to the original wndProc.

So, yes, all you have to do is register the key and handle the event.


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Fri Mar 30, 2012 4:50 pm 
Offline

Joined: Sat Jul 16, 2011 2:45 pm
Posts: 76
Hey guys, thank you once again.

Managed to get it to "work" at last.

It works just about everywhere except for one application (a game) which is where I actually wanted it to work! (works in other games though). Just wondering if any of you guys might know why this is the case?

Im assuming this game takes control of all input while it is in focus, and doesn't let any messages /key binding go outside onto the message queue?


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Fri Mar 30, 2012 7:24 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
I've had this same problem and don't know of a solution. :(

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Sat Mar 31, 2012 3:50 pm 
Offline

Joined: Sat Jul 16, 2011 2:45 pm
Posts: 76
Is there anyway to do global hook with realstudio? I'm guessing you can't create a DLL with realstudio so I'm almost certainly screwed I'm guesssing?


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Sat Mar 31, 2012 4:10 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
I don't see why not, as long as there's an API for it, which there has to be.


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Sat Mar 31, 2012 4:48 pm 
Offline

Joined: Sat Jul 16, 2011 2:45 pm
Posts: 76
global hooks require you make a DLL to handle it all, as windows will "call" that DLL as part of a chain, but realstudio doesn't allow creations of DLL's IIRC?


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Sat Mar 31, 2012 8:01 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Can you make a dll with some other tool and register your callback with the dll when you register the hook? My memory of global hooks is very fuzzy at the moment.


Top
 Profile  
Reply with quote  
 Post subject: Re: Register hotkey?
PostPosted: Sun Apr 01, 2012 12:58 pm 
Offline

Joined: Sat Jul 16, 2011 2:45 pm
Posts: 76
After looking at Microsoft's documentation again I think it is possible without a DLL + windows functionality suit has it already too so think I should be able to do what I needed afterall. Just want to thank you two for your help :)


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

All times are UTC - 5 hours


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group