Sign in to follow this  
Followers 0
Morel

HotKey Issue

6 posts in this topic

I Have Autoit Application And i Define a HotKey Thet When I Press The {Enter} Button Its

Do a ControlClick So far so good.

But When i am Work With Any Other Application When i Press The {Enter} Key its Lunch Again The

Autoit Script

How Can i Solve That only when the Autoit Application is in focus The HotKey Will Work

Othwise It Act Normaly

10X

Morel

Share this post


Link to post
Share on other sites



WinActive ()


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

I Didnt Understand You Can You Give me an Exapmle Please

Thanks

Morel

Share this post


Link to post
Share on other sites

I Have Try To Use WinActive() Function Using This Code

HotKeySet("{Enter}","HotKeyTest")

Func HotKeyTest()

If WinActive ("AForm1","") Then

ControlClick("","",$Button1)

EndIf

EndFunc

But When The Application is not in Focus I Cant Use The Enter Key

any Idea Somone ?

Morel

Share this post


Link to post
Share on other sites

Hello Morel Try This Nice Exmaple

#include <GuiConstants.au3>
HotKeySet("{ENTER}", "catchguikey")
$gui = GuiCreate("Hotkey Test")
GuiCtrlCreateLabel("Press Enter", 0, 0)
GuiSetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Func catchguikey()
    Local $opt = Opt("WinTitleMatchMode", 4)
    If WinGetHandle("active") = $gui Then
        If @HotKeyPressed = "{ENTER}" Then
           ;Do something here
            ToolTip("Key Pressed")
            Sleep(1000)
            ToolTip("")
        EndIf
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "catchguikey")
    EndIf
    Opt("WinTitleMatchMode", $opt)
EndFunc

Krikov


[topic="63488"][font="Arial"]Krikov Tray Quick Menu[/font][/topic]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Quick and untested, but should work.

$regged = 0
$title = "AForm1"
$Button1 = "Button1"

While 1
    ; register if window is active and hotkey isn't registered
    If $regged = 0 AND WinActive($title) Then
        $regged = 1
        HotKeySet("{Enter}", "HotKeyTest")
    EndIf
    
    ; unregister if window isn't active and hotkey is registered
    If $regged = 1 AND NOT WinActive($title) Then
        $regged = 0
        HotKeySet("{Enter}")
    EndIf
    
    Sleep(10)
WEnd

Func HotKeyTest()
    ControlClick("","",$Button1)
EndFunc

Edited by Helge

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