Sign in to follow this  
Followers 0
qwert

Can a function key be intercepted?

6 posts in this topic

I have one of the low-cost presenters -- a usb-based remote control that sends F5 as one of its four buttons. I'd like to use F5 to initiate a feature in my script. By using _IsPressed, I can indeed receive the key and act on it. The problem is the F5 click is being passed on to another application, which results in an extraneous message on the screen. The only reference I can find related to F5 is this:

To refresh the active window in IE or WE, press F5.

I've searched these forums, but the only key intercept techniques seem to be related to catching characters going into an input control. Is there a way to assign F5 to my application so that it is "captured" and not seen by other apps?

Thanks in advance for any help.

Share this post


Link to post
Share on other sites



Thanks for your suggestion. I had gotten off that track (from hotkeys) when I started using _IsPressed for my other key selections.

But now, I've run into a different problem. Apparently the presenter's usb device manager behaves as a separate application. It seems to detect its own F5 button -- and will "send" it to my script, so that it gets detected by _IsPressed, but the operating system and my script's HotKeySet never receive the key press. Yet, if I press F5 on the keyboard, my HotKeySet function executes immediately.

I've also found this in the AutoIt Help:

The following hotkeys cannot be set: ....F12 -- reserved by Windows ... Other -- Any global hotkeys a user has defined using third-party software.

I'm going to have to think about this some more.

Share this post


Link to post
Share on other sites

I have one of the low-cost presenters -- a usb-based remote control that sends F5 as one of its four buttons.  I'd like to use F5 to initiate a feature in my script.  By using _IsPressed, I can indeed receive the key and act on it.  The problem is the F5 click is being passed on to another application, which results in an extraneous message on the screen.  The only reference I can find related to F5 is this:

I've searched these forums, but the only key intercept techniques seem to be related to catching characters going into an input control.  Is there a way to assign F5 to my application so that it is "captured" and not seen by other apps?

Thanks in advance for any help.

qwert

your usb device works at the hardware driver level and may be unhookable;

this probably wont work, but give it a try.

a quick reworking of help file example for _WinAPI_SetWindowsHookEx to show low level keyboard hook of F5 key

you can process F5, then either block or pass it on to other apps

you should return quickly from the _KeyProc function, i.e. no blocking msgbox, loops, sleep etc.

or the pc will become unresponsive.

Use ESC key to exit the script - this will properly close hook and callback in _OnAutoItExit()

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>

OnAutoItExitRegister("_OnAutoItExit")
Opt('MustDeclareVars', 1)

Global $iF5Key = False
Global Const $VK_F5 = 0x74 ;F5 key
Global Const $VK_ESCAPE = 0x1B ;ESC key
Global $hHook, $hStub_KeyProc, $iDLLUSER32 ; globals required for hook
$iDLLUSER32 = DllOpen("user32.dll")

_Main()

Func _Main()
    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    Local $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)

    While 1
        Sleep(50)
        If $iF5Key = True Then ;place in your message loop. you can use global or GuiCtrlSendToDummy() in EvaluateKey or _KeyProc
            $iF5Key = False
            ConsoleWrite("!F5 Blocked" & @CRLF)
            ;do your own processing after blocking F5
        EndIf
    WEnd
EndFunc   ;==>_Main

Func EvaluateKey($keycode)
    If ($keycode = $VK_F5) Then
        $iF5Key = True
        Return 1 ;to block F5 to other apps
        ;Return 0 ; allow F5 to pass
    ElseIf ($keycode = $VK_ESCAPE) Then ; esc key
        Exit
    EndIf
    Return 0
EndFunc   ;==>EvaluateKey

;===========================================================
; callback function
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then ;must return if $nCode less than zero
        Return __WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    If $wParam = $WM_KEYDOWN Then
        If EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode")) = 1 Then Return 1
    Else
        Local $flags = DllStructGetData($tKEYHOOKS, "flags")
        Switch $flags
            Case $LLKHF_ALTDOWN
                ;ConsoleWrite("$LLKHF_ALTDOWN" & @LF)
            Case $LLKHF_EXTENDED
                ;ConsoleWrite("$LLKHF_EXTENDED" & @LF)
            Case $LLKHF_INJECTED
                ;ConsoleWrite("$LLKHF_INJECTED" & @LF)
            Case $LLKHF_UP
                ;ConsoleWrite("$LLKHF_UP: scanCode - " & DllStructGetData($tKEYHOOKS, "scanCode") & @TAB & "vkCode - " & DllStructGetData($tKEYHOOKS, "vkCode") & @LF)
        EndSwitch
    EndIf
    Return __WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func _OnAutoItExit()
    ;unhook keyboard, free callback, close open dll
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
    DllClose($iDLLUSER32)
EndFunc   ;==>OnAutoItExit

Func __WinAPI_CallNextHookEx($hhk, $iCode, $wParam, $lParam)
    Local $aResult = DllCall($iDLLUSER32, "lresult", "CallNextHookEx", _
    "handle", $hhk, "int", $iCode, "wparam", $wParam, "lparam", $lParam)
    If @error Then Return SetError(@error, @extended, -1)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_CallNextHookEx

I see fascists...

Share this post


Link to post
Share on other sites

qwert

ignore my post above

go with Yashieds Hotkey UDF

I should have read it first

why are posts uneditable or deleteable?


I see fascists...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0