Sign in to follow this  
Followers 0
Raymond

Need help on HotKeySet function

10 posts in this topic

#1 ·  Posted (edited)

Hello all!

Here is my little try with AI3

Opt("WinTitleMatchMode", 4)

HotKeySet("{ENTER}", "_Enter")

Run("cm.exe")

While 1

Sleep(1000)

WEnd

Func _Enter()

If WinActive("classname=obj_Form") Then

....

; do something

...

EndIf

EndFunc

When cm.exe is in front, it works fine as I design.

But if switch to other window, "ENTER" key doesn't work there. It's captured by the script, I guess. And If statment doesn't avoid that.

What can I do to make Enter key do as I design when cm.exe window is active, and works as it is when other windows are active?

Edited by Raymond

Share this post


Link to post
Share on other sites



Personally I would not use the enter key for a hotkey. I suggest using one of the function keys or unsetting the hotkey inside the function.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Tested with the AutoIt Helpfile.

Global $hotkey, $title = "AutoIt Help" ;"classname=obj_Form"
Opt("WinTitleMatchMode", 4)
;Run("cm.exe")

While 1
    If WinActive($title) And Not $hotkey Then
        $hotkey = HotKeySet("{ENTER}", "_Enter")
    ElseIf Not WinActive($title) And $hotkey Then
        HotKeySet('{ENTER}')
        $hotkey = 0
    EndIf
    Sleep(1000)
WEnd

Func _Enter()
    ConsoleWrite('HotKey is On' & @LF)
EndFunc

:D

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Personally I would not use the enter key for a hotkey. I suggest using one of the function keys or unsetting the hotkey inside the function.

Yes I can change the hotkey.

But I want to know how to make HotKeySet function only apply to specific window, keeping others as they always are.

I bet AI3 can do that, only I don't know yet.

Edited by Raymond

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yes I can change the hotkey.

But I want to know how to make HotKeySet function only apply to specific window, keeping others as they always are.

I bet AI3 can do that, only I don't know yet.

If WinActive('The window you want the hotkey for') Then

     HotKeySet('{ENTER}', "_Enter")

Else

     HotKeySet('{ENTER}') ; cancels hotkey

EndIf

Nomad :D

Edited by Nomad

Share this post


Link to post
Share on other sites

If WinActive('The window you want the hotkey for') Then

     HotKeySet('{ENTER}', "_Enter")

Else

     HotKeySet('{ENTER}') ; cancels hotkey

EndIf

Nomad :D

Yeah! This does the trick.

Thanks for your help.

Only still don't get why If statement (as first floor) doesn't work as it should be.

Share this post


Link to post
Share on other sites

Yeah! This does the trick.

Thanks for your help.

Only still don't get why If statement (as first floor) doesn't work as it should be.

Because you only want the Hotkey to effect "your active" window, not the others as you stated. The hotkey is activated when the window is active and deactivated when it isn't.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Because you only want the Hotkey to effect "your active" window, not the others as you stated. The hotkey is activated when the window is active and deactivated when it isn't.

In my first post my code is like

Func _Enter()

If WinActive("classname=obj_Form") Then

....

; do something

...

EndIf

EndFunc

It seems to me not big difference from Nomad's code. But only his one works.

I wonder why.

Share this post


Link to post
Share on other sites

Yeah! This does the trick.

Thanks for your help.

No problem, just put that into a function and call the function anytime the window changes and it will enable/disable the hotkey as needed. There are other methods you could also do, but this is probably the simplest method.

As far as the hotkey functioning/not functioning... a hotkey cannot be assigned by AutoIt if it is already assigned by another program. Likewise, if the hotkey is already reserved by your script, it probably cannot be assigned by another program.

There are ways around this though, as has been proven by the "full screen" mode of some games. I've started scripts before starting a full screen game, and the game automatically blocked my hotkeys and wouldn't allow them to function while in full screen. But the game hotkeys, even when the keys were the same as in my script, still functioned. So, there is a way, but I don't know it, yet. :D

Nomad :D


Share this post


Link to post
Share on other sites

@Nomad

Thanks for the explanation.

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