Jump to content

How To Unregister Hotkey When Window Not Active...


Recommended Posts

Hey guys,

I have a script here that I am unclear on where to unregister the hotkey so that it doesn't work in any other window than the one I define.

;==============================================================================
; Description: Close Remedy Window When Pressing Ctrl+R
; AutoIT Version: 3.1.114 beta
; Author: neoborn
; Creation Date: 30th March 2006
;==============================================================================
#include <GUIConstants.au3>
#include <File.au3>

Opt ("TrayIconDebug", 1)
Opt ("GuiOnEventMode", 0)
Opt ("GuiCloseOnEsc", 1)
;Opt ("TrayMenuMode", 0) ; Default tray menu items (Script Paused/Exit) will not be shown.
Opt ("WinTitleMatchMode", 1)
;-----------------------------------------------------------------------------------------------------
; Pseudo Code
; 1. Sits and sleeps in system tray until
; 2. Ctrl + f are pressed causing the function to run
; 3. The function goes to the mouse coordinates and clicks the left mouse button to close the window
;-----------------------------------------------------------------------------------------------------
HotKeySet("^f", "Pressed")
Dim $i = 0, $PushTime = 300


While 1
    If WinActive("Login - Remedy User","") Then 
        Login()
    EndIf
    Sleep(100); Sleep in until something happens i.e. the hotkey is pushed.
WEnd

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func Pressed()
    $i += 1
    Sleep($PushTime)
    Select
        Case $i = 1
            ClsWin()
        Case $i = 2
            CompTck()
        Case $i = 3
            
        case $i = 4
            Exit(0)
    EndSelect
    $i = 0
    
EndFunc  ;==>Pressed

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;   
Func ClsWin()
    Send("^{F4}")
EndFunc   ;==>ClsWin
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;    
Func Login()
        WinActivate("Login - Remedy User","")
        Send("username{TAB}password")
        ControlFocus("Login - Remedy User", "OK", 1)
        ControlClick("Login - Remedy User", "OK", 1)
EndFunc

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func CompTck()
    Send("^i")
    WinWait("Run Macro","Macro's &Path:")
    If Not WinActive("Run Macro","Macro's &Path:") Then WinActivate("Run Macro","Macro's &Path:")
        WinWaitActive("Run Macro","Macro's &Path:")
        Send("{TAB}{TAB}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}")
        ControlFocus("Run Macro", "OK", 1)
        ControlClick("Run Macro", "OK", 1)
EndFunc

Can anyone explain to me what command and where I should unregister the hotkey from ?

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Link to comment
Share on other sites

pseudocode cuz im lazy.

Func Pressed()

if not winactive(self) then

reset hotkey

send hotkey

reasign hotkey

return

endif

...

EndFunc ;==>Pressed

what's this

reset hotkey

send hotkey

reasign hotkey

I thought to unassign the hotkey I just repeat the command. First hotkey command assigns then next one unassigns. Is this right?

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Link to comment
Share on other sites

what's this

reset hotkey

send hotkey

reasign hotkey

I thought to unassign the hotkey I just repeat the command. First hotkey command assigns then next one unassigns. Is this right?

yes u do hotkeyset("{KEY}") - unassigns it

then u send"{KEY}" on as another app may need that keypress

then u reassign the hot key again for your app

hotkeyset"{KEY},"func")

hth

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

yes u do hotkeyset("{KEY}") - unassigns it

then u send"{KEY}" on as another app may need that keypress

then u reassign the hot key again for your app

hotkeyset"{KEY},"func")

hth

HardCopy

Hmm I still don't quite understand.

This was working fine in previous version of the program:

HotKeySet("^r", "ClsWin")

Dim $avArray[4]
$avArray[0] = "Enterprise Services Helpdesk - [ES_HD (Modify)]"
$avArray[1] = "Enterprise Services Helpdesk - [ES_HD (New)]"
$avArray[2] = "Enterprise Services Helpdesk - [ES_HD (Search)]"

Func ClsWin()
    $title = WinGetTitle($avArray[0], "") Or WinGetTitle($avArray[1], "") Or WinGetTitle($avArray[2], "")
    If ProcessExists("aruser.exe") And $title <> 0 Then
        Send("^{F4}")
    EndIf
    HotKeySet("^r", "ClsWin")
EndFunc   ;==>ClsWin

It works fine in this version but if I follow the example of the above in my new version by putting the hot key after the if statement it doesn't work.

Can someone show me in code how they would do this in the first code I pasted so I can understand the concept please ?

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Link to comment
Share on other sites

While 1
    If WinActive("Login - Remedy User","") Then
        Login()
    Else
        HotKeySet("^f"); Unassign
        Send("^f")  ; send it on 
        HotKeySet("^f", "Pressed"); reassign
    EndIf   
        Sleep(100); Sleep in until something happens i.e. the hotkey is pushed.
WEnd

nb: not tested

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

While 1
    If WinActive("Login - Remedy User","") Then
        Login()
    Else
        HotKeySet("^f"); Unassign
        Send("^f"); send it on 
        HotKeySet("^f", "Pressed"); reassign
    EndIf   
        Sleep(100); Sleep in until something happens i.e. the hotkey is pushed.
WEnd

nb: not tested

HardCopy

I will try that, also I have another question. If I assign a variable like the below how come it states as an error saying it is being used before declaration?

#include <File.au3>

Opt("WinTitleMatchMode", 1)

win()

Global $title = "hi"

Func win()
    MsgBox("", "Current Window", "The current active window is " & $title)
EndFunc

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Link to comment
Share on other sites

I will try that, also I have another question. If I assign a variable like the below how come it states as an error saying it is being used before declaration?

#include <File.au3>

Opt("WinTitleMatchMode", 1)

Global $title = "hi" 

win()



Func win()
    MsgBox("", "Current Window", "The current active window is " & $title)
EndFunc

Try it now . swapped 2 lines around

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

Thank you very much. I still haven't got the hotkey thing working right I think the problem is with the active window. But the global thing works fine ty

So I guess Global variables must be declared right after include and opt etc.

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

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