Jump to content
Sign in to follow this  
Zohar

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

Recommended Posts

Zohar

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

Share this post


Link to post
Share on other sites
LiveOnTheFly

lookup WinActive and _IsPressed in the helpfile

Share this post


Link to post
Share on other sites
Bert

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.