Windows hotkeys in Ruby

N

Nicolas Delsaux

Hi,
as a tutorial to Ruby learning, I'm trying to create a clone of a
Windows program, RndSig, which allows, from the stroke of a "global
hotkey" (I don't know if this expression is fully exact), to take the
content of current text editor in order to choose from it the most
accurate signature.
The signature selection has already been done.
But, now, I want to be able to execute the active part of the script
(launching can occur at session start) from a hotkey, and allow it to
copy the content of the current text area.
Is it possible using Ruby ? I think it will imply some use of the
WIN32API "module" (is it the right word ?), but how ...
From the initial program, the content of the text area was copied to
the clipboard, and then used in the program (don't know if it can be
of any help). And, were you willing to test it, it is available at
http://www.lacave.net/~fred/divers/rndsig.html
Thanks
 
B

Bill Kelly

From: "Nicolas Delsaux said:
But, now, I want to be able to execute the active part of the script
(launching can occur at session start) from a hotkey, and allow it to
copy the content of the current text area.
Is it possible using Ruby ? I think it will imply some use of the
WIN32API "module" (is it the right word ?), but how ...

There's RegisterHotKey()
http://www.google.com/search?hl=en&q=registerhotkey

You might be able to call that via Win32API, but, you'll
need a window handle too.


Regards,

Bill
 
N

Nicolas Delsaux

There's RegisterHotKey()
http://www.google.com/search?hl=en&q=registerhotkey

You might be able to call that via Win32API, but, you'll
need a window handle too.

Thanks.
From what I can see, " If this parameter is NULL, WM_HOTKEY messages
are posted to the message queue of the calling thread and must be
processed in the message loop.". Is it to say that, provided i have a
running Ruby thread (or the local equivalent to this Java word)
running, I will be able to recieve "events" ?
If it is the case, it seems to me rather simple, isn't it ?

--
Nicolas Delsaux
"Chasseur-elle-bat-le-beurre a des idées bien arrêtées sur la
dynamique sémantique de la taxonomie idéologique"
Chasseur-idiot alias Socrate in frjn en tant que métaphore
conceptuelle économique
 
B

Bill Kelly

From: "Nicolas Delsaux said:
Thanks.
From what I can see, " If this parameter is NULL, WM_HOTKEY messages
are posted to the message queue of the calling thread and must be
processed in the message loop.". Is it to say that, provided i have a
running Ruby thread (or the local equivalent to this Java word)
running, I will be able to recieve "events" ?
If it is the case, it seems to me rather simple, isn't it ?

Ah - cool, I missed the part about passing in NULL.

Note, that all Ruby threads really run in the same operating
system thread. This means if you call an operating system
function that blocks, all of your ruby threads will wait until
it returns. This can sometimes make things challenging; but
for what you're doing I don't think it will be an issue.

Sounds like you can call RegisterHotKey() ... then start calling
either PeekMessage() or GetMessage() and watch for your WM_HOTKEY
messages.


Regards,

Bill
 
D

daz

Nicolas said:
Hi,
as a tutorial to Ruby learning, I'm trying to create a clone of a
Windows program, RndSig, which allows, from the stroke of a "global
hotkey" (I don't know if this expression is fully exact), to take the
content of current text editor in order to choose from it the most
accurate signature.

If you get stuck on this and just want to get it done, you might
consider creating a Windows shortcut to "ruby rndsig.rb", then
add a global hotkey to the shortcut's "Properties".

Pressing the global hotkey will fire up "rndsig.rb" which would
need to find the "source" window, copy the text, choose a .sig
based on that text, then paste it back and close.

http://www.rubygarden.org/ruby?AutoIt_For_Windows
would facilitate that.

You'll learn more by doing it the hard way but I'd suggest that
Ruby (on its own) isn't your best tool for this.


daz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top