Forum: Ruby global hotkeys in windows.

Posted by Ted Flethuseo (flethuseo)
on 2010-10-23 16:11
I built a script that does a job for me, and I'd like to call from time
to time, even when the script isn't running. Is there a way I can assign
a global hot key in ruby so that whenever I press the hotkey it launches
it.

Ted.
Posted by Eric Christopherson (Guest)
on 2010-10-23 16:39
(Received via mailing list)
On Sat, Oct 23, 2010 at 9:11 AM, Ted Flethuseo <flethuseo@gmail.com> 
wrote:
> I built a script that does a job for me, and I'd like to call from time
> to time, even when the script isn't running. Is there a way I can assign
> a global hot key in ruby so that whenever I press the hotkey it launches
> it.

You'd need to use something like AutoHotkey for that. I've never used
it with Ruby, but it could be done.
Posted by Jethrow .. (jethrow)
on 2010-10-23 20:53
Eric Christopherson wrote in post #956560:
> You'd need to use something like AutoHotkey for that. I've never used
> it with Ruby, but it could be done.

AutoHotkey would be more my area of knowledge. You might be interested
that AHK now has a DLL with COM support. This would make embedding AHK
in Ruby quite simple:

    require "WIN32OLE"

    code =  "#NoTrayIcon\n" +
            "^m:: MsgBox, Hotkey created with AHK in Ruby"

    ahk = WIN32OLE.new("AutoHotkey.Script")
    ahk.AhkTextDll(code)

    puts "Press CTRL+M to display a Message Box with embedded AHK\n\n" +
         "Hit Enter to close the console & destroy the Hotkey ..."
    gets

If you want to know more, the AHK topic is here:
http://www.autohotkey.com/forum/topic43049.html

The actual DLL is part of the PACKAGE referenced here:
http://www.autohotkey.net/~HotKeyIt/AutoHotkey/

NOTE - you'd have to register the DLL using regsvr32.exe (or you could
use the DLL directly w/o the COM interface)
Posted by Ted Flethuseo (flethuseo)
on 2010-10-25 04:51
Hi,
This is cool. I was wondering though.. is it preferable to copy the 
AutoHotkey.dll file to some special location before registering it, or 
does registering it mean that it actually copies it to some windows 
directory. (Is there a specific windows directory for dlls?)

Ted

Jethrow .. wrote in post #956604:
> Eric Christopherson wrote in post #956560:
>> You'd need to use something like AutoHotkey for that. I've never used
>> it with Ruby, but it could be done.
>
> AutoHotkey would be more my area of knowledge. You might be interested
> that AHK now has a DLL with COM support. This would make embedding AHK
> in Ruby quite simple:
>
>     require "WIN32OLE"
>
>     code =  "#NoTrayIcon\n" +
>             "^m:: MsgBox, Hotkey created with AHK in Ruby"
>
>     ahk = WIN32OLE.new("AutoHotkey.Script")
>     ahk.AhkTextDll(code)
>
>     puts "Press CTRL+M to display a Message Box with embedded AHK\n\n" +
>          "Hit Enter to close the console & destroy the Hotkey ..."
>     gets
>
> If you want to know more, the AHK topic is here:
> http://www.autohotkey.com/forum/topic43049.html
>
> The actual DLL is part of the PACKAGE referenced here:
> http://www.autohotkey.net/~HotKeyIt/AutoHotkey/
>
> NOTE - you'd have to register the DLL using regsvr32.exe (or you could
> use the DLL directly w/o the COM interface)
Posted by Jethrow .. (jethrow)
on 2010-10-25 06:34
Ted Flethuseo wrote in post #956795:
> ... does registering it mean that it actually copies it to some windows
> directory. (Is there a specific windows directory for dlls?

Registering does not create a copy. Registering will make it so you can
create a COM object (WIN32OLE.new), but the DLL will remain wherever it
was when you registered it. Personally, I keep it in the same directory
as my AHK installation. However, many DLL files are located in the
Windows Directory.

On a side note, the maintainer of the DLL has been updating it regularly
recently. He provided a direct link for the Windows (32 bit) Unicode
version: http://www.autohotkey.net/~HotKeyIt/AutoHotkey.dll
Posted by Eric Christopherson (Guest)
on 2010-10-26 09:26
(Received via mailing list)
On Sun, Oct 24, 2010 at 11:34 PM, Jethrow .. <jethrow@gmx.com> wrote:
> On a side note, the maintainer of the DLL has been updating it regularly
> recently. He provided a direct link for the Windows (32 bit) Unicode
> version: http://www.autohotkey.net/~HotKeyIt/AutoHotkey.dll

To practice a little bit, I made some simple scripts to demonstrate
using AutoHotkey with Ruby, and put them on GitHub. What I have so far
is at:

http://github.com/echristopherson/ahk_drb_demo
Posted by Ted Flethuseo (flethuseo)
on 2010-10-26 13:36
Thanks Eric.
That will be useful for sure.

Ted


Eric Christopherson wrote in post #957129:
> On Sun, Oct 24, 2010 at 11:34 PM, Jethrow .. <jethrow@gmx.com> wrote:
>> On a side note, the maintainer of the DLL has been updating it regularly
>> recently. He provided a direct link for the Windows (32 bit) Unicode
>> version: http://www.autohotkey.net/~HotKeyIt/AutoHotkey.dll
>
> To practice a little bit, I made some simple scripts to demonstrate
> using AutoHotkey with Ruby, and put them on GitHub. What I have so far
> is at:
>
> http://github.com/echristopherson/ahk_drb_demo
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.