Jump to content

HotKey Issue


Morel
 Share

Recommended Posts

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

Link to comment
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

Link to comment
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]

Link to comment
Share on other sites

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
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...