Home   Archive   Permalink



Key hooker

Hi,
    
I am looking to develop a key-hooker which will detect when, using a text editor such as notepad, I press a function key (for example F10).
I saw the engage and detect feel function but I can't understand if it work when the focus is not on the Rebol application (in this case, the focus is in notepad).
Do you have any advice on how to do that (how to detect pressed keys in the background)?
    
Thx

posted by:   Maomao       20-Mar-2012/9:17:32-7:00



On Windows, use the system API for that:
    
RegisterHotKey
"The RegisterHotKey function defines a system-wide hot key."
    
'declaration for vb, you can convert it to REBOL
Declare Function RegisterHotKey Lib "user32" Alias "RegisterHotKey" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
    
    
UnregisterHotKey
"The UnregisterHotKey function frees a hot key previously registered by the calling thread."
    
Declare Function UnregisterHotKey Lib "user32" Alias "UnregisterHotKey" (ByVal hwnd As Long, ByVal id As Long) As Long
    
Search for API-Guide or AllApi.net you can find examples there.
    
Hope this helps.


posted by:   Endo       21-Mar-2012/7:47:17-7:00



Thx a lot, I will have a look a this and keep you updated

posted by:   maomao       23-Mar-2012/6:15:46-7:00



Take a look at http://re-bol.com/rebol.html#section-9.8 to learn how to actions Windows API functions.
    
Here's the first VB example above converted to a REBOL function:
    
lib: load/library %user32.dll
    
RegisterHotKey: make routine! [
     return: [integer!]
     hwnd [integer!]
     id [integer!]
     fsModifiers [integer!]
     vk [integer!]
] lib "RegisterHotKey"
    
; Once an imported function is defined, use it like any other REBOL function:
    
RegisterHotKey hwnd id fsModifiers vk
    
; Close the library when done:
    
free lib

posted by:   Nick       23-Mar-2012/21:21:31-7:00