Jump to content

[Solved] How to Capture a KeyPress in One Application, but Ignore it(and pass it) in Another


Recommended Posts

Hello

I would like to to this:

I would like to make a small script, that Captures F1(for example) when I am in Application 1, and handle it somehow,

but in all other applications, the script will ignore it and pass it to whatever application that I am working on.

Opt("MustDeclareVars",1)

HotKeySet("{F1}" ,"Handler")


Func Handler()
    If WinGetTitle("")="SOME APPLICATION" Then
        MsgBox(0,"","F1 was Handled.")
    Else
        ControlSend("","","",@HotKeyPressed)
    EndIf
EndFunc

While 1
    Sleep(100)
WEnd

now,

my problem is in the "Passing the Key to other applications" part.

I used ControlSend("","","",@HotKeyPressed), but I am not sure it works very well.

for example, open Paint.exe and try it

the script tries to pass it to current application(paint), but the help window is not opened.

If you stop the script and then press F1 in paint, the help window will open, as should.

what should I do?

any other line instead of ControlSend("","","",@HotKeyPressed)?

or maybe there's even a better way,

for example, instead of capturing and then passing it, maybe another way that doesn't capture it in the "other" applications?

Thank you

Edited by Zohar
Link to comment
Share on other sites

Try this in managing when a window is active or not. This is what I use to handle hotsetkeys on certain windows only. :

HotKeySet("{F2}", "HotKeyFunc")
HotKeySet("{ESC}", "HotKeyFunc")

While 1
    Sleep(100) ;idle around
    ; Script part
WEnd

Func HotKeyFunc()
    If WinActive("") Then; Set the window
        Switch @HotKeyPressed
            Case "{F2}"
                ;;;
            Case "{ESC}"
                Exit
        EndSwitch
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "HotKeyFunc")
    EndIf
EndFunc
Edited by Volly
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...