Jump to content

Even when "Paused" hot key is still overtaken


Recommended Posts

I have a program that runs in the system tray and acts as a hot key assistant for the F11 key. When I "Pause" the script I expect that the F11 key control will get turned back over to the computer. But, it seems as though the F11 key is disabled for all programs when the script is paused. What can I do to turn over F11 functionality back to the computer when the script is paused?

Here's my code:

Global $Paused
Global $Location

AutoItSetOption("TrayAutoPause",0)
Hotkeyset("{F11}","MainFunction")

While 1
    Sleep(100)
WEnd


Func MainFunction()
if @DesktopWidth=1024 and @DesktopHeight=768 then
blockinput(1)
$sleeptime="250"
;===========================
;Determine Location Based on Open windows.
;===========================
$var = WinList()
$location=""

For $i = 1 to $var[0][0]
  If BitAnd( WinGetState($var[$i][1]), 2 ) Then 
    $t=true
  Else
    $t=false
  EndIf
  ; Only display visble windows that have a title
  If $var[$i][0] <> "" AND $t Then
      Consolewrite($var[$i][0]&@CRLF)
        ;consolewrite("Title=" & $var[$i][0])
            if StringInStr($var[$i][0],"Hospital_1") Then
                $location="Hospital_1"
            ElseIf StringInStr($var[$i][0],"Hospital_2") Then
                $location="Hospital_2"
            Else 
                if StringInStr($var[$i][0],"Hospital_3") Then
                    $location = "Hospital_3"
                EndIf
            EndIf
    EndIf
Next

;===========================
;End determining Location Based on Open windows.
;===========================

    if WinExists(""&$location&"","") then
        WinActivate(""&$location&"","")
        WinMove(""&$location&"", "", 0, 0)
        MouseClick("left",391,212,1,0)
        WinWaitActive("Coder Desktop -", "", 10)
        WinMove("Coder Desktop -", "", 0, 0)
        Send("{space}")
        Send("{enter}")
        Send("{tab}")
        $counter=0
        do
            Sleep($sleeptime)
            MouseClick("left",537,687,1,0)
            $counter=$counter+1
            if $counter=5 Then
                if WinExists("Enterprise Medical Record","") then
                    ExitLoop
                EndIf
            EndIf
        Until $counter > 20
        if not WinExists("Enterprise Medical Record","") then
            blockinput(0)
            MsgBox(0,"Warning","Operation may not have successfully complete because the selected record took too long to appear")
        EndIf
    Else
        blockinput(0)
        Msgbox(0,"Warning","Can not start hotkey sequence because Meditech "&$location&" screen is not open")
    EndIf
    
    Else
        MsgBox(0,"Error","Your resolution is not set to 1024x768.  Please set your resolution to 1024x768 before continuing.")
    EndIf
    
    blockinput(0)
EndFunc

Func Terminate()
    Exit 0
EndFunc
Link to comment
Share on other sites

  • Moderators

inm101,

How are you pausing your script? You have a $Paused variable declared, but it is never used. :(

If you were to use a second HotKey to pause/unpause the script, you could then unset/reset the existing HotKey within the same function. her is an example of how to do it: :)

#include <GUIConstantsEx.au3>

HotKeySet("{F1}", "Run_Function")
HotKeySet("{F2}", "Pause_Function")

$fPaused = False

$hGUI = GUICreate("Test", 500, 500)

$hLabel_1 = GUICtrlCreateLabel("", 10, 10, 300, 20)
$hLabel_2 = GUICtrlCreateLabel("", 10, 50, 300, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func Run_Function()

    GUICtrlSetData($hLabel_1, "The F1 Hotkey is working")
    Sleep(1000)
    GUICtrlSetData($hLabel_1, "")

EndFunc

Func Pause_Function()

    $fPaused = Not $fPaused
    If $fPaused = True Then
        HotKeySet("{F1}")
        GUICtrlSetData($hLabel_2, "Paused!")
    Else
        HotKeySet("{F1}", "Run_Function")
        GUICtrlSetData($hLabel_2, "")
    EndIf

EndFunc

Please ask if anything is unclear. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

inm101,

How are you pausing your script? You have a $Paused variable declared, but it is never used. :(

If you were to use a second HotKey to pause/unpause the script, you could then unset/reset the existing HotKey within the same function. her is an example of how to do it: :)

#include <GUIConstantsEx.au3>

HotKeySet("{F1}", "Run_Function")
HotKeySet("{F2}", "Pause_Function")

$fPaused = False

$hGUI = GUICreate("Test", 500, 500)

$hLabel_1 = GUICtrlCreateLabel("", 10, 10, 300, 20)
$hLabel_2 = GUICtrlCreateLabel("", 10, 50, 300, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func Run_Function()

    GUICtrlSetData($hLabel_1, "The F1 Hotkey is working")
    Sleep(1000)
    GUICtrlSetData($hLabel_1, "")

EndFunc

Func Pause_Function()

    $fPaused = Not $fPaused
    If $fPaused = True Then
        HotKeySet("{F1}")
        GUICtrlSetData($hLabel_2, "Paused!")
    Else
        HotKeySet("{F1}", "Run_Function")
        GUICtrlSetData($hLabel_2, "")
    EndIf

EndFunc

Please ask if anything is unclear. :)

M23

I don't want to create another hot key to pause/unpause. I just don't want "Pause" to disable the F11 key all together. And, let me be more specific. The F11 key only seems to be disabled for one program. It's a Medicare Telnet-driven program.

I'm not sure what to do at this point other than creating two scripts...One to run as the actual F11 function and one to run as a system tray Opener and Exiter.

Edited by inm101
Link to comment
Share on other sites

  • Moderators

inm101,

When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :(

creating two scripts...One to run as the actual F11 function and one to run as a system tray Opener and Exiter

You can still do it in one script. :) How about using the tray icon menu to enable/disable your F11 HotKey? This shows how it could be done:

#include <GUIConstantsEx.au3>

HotKeySet("{F11}", "Run_Function")

$fDisable = False

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

Global $hPause_Item = TrayCreateItem("Disable F11")
TrayItemSetOnEvent(-1, "On_Option")
TrayCreateItem("")
Global $hExit_Item = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")
TrayCreateItem("")

$hGUI = GUICreate("Test", 500, 500)

$hLabel_1 = GUICtrlCreateLabel("", 10, 10, 300, 20)
$hLabel_2 = GUICtrlCreateLabel("", 10, 50, 300, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func Run_Function()

    GUICtrlSetData($hLabel_1, "The F11 Hotkey is working")
    Sleep(1000)
    GUICtrlSetData($hLabel_1, "")

EndFunc

Func On_Option()

    $fDisable = Not $fDisable
    If $fDisable = True Then
        HotKeySet("{F11}")
        GUICtrlSetData($hLabel_2, "F11 Disabled!")
        TrayItemSetText($hPause_Item, "Enable")
    Else
        HotKeySet("{F11}", "Run_Function")
        GUICtrlSetData($hLabel_2, "")
        TrayItemSetText($hPause_Item, "Disable")
    EndIf

EndFunc

Func On_Exit()
    Exit
EndFunc

Is that more what you want?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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