Jump to content
Sign in to follow this  
mjolnirmarkiv

Smth like HotKeySet but on event

Recommended Posts

mjolnirmarkiv

Hi,

So here's the deal. I wrote a script that process Excel file and input information to database on the server. Since I cannot access it directly for security reasons, I'm working through a separate application, a client, with various ControlClicks and ControlCommands etc. The problem though is that the client is lagging wildly depending on the remote desktop I'm using, so I've used WinWait and WinWaitClose, plus I'm running following loop from time to time in some places I expect a severe lag (like TreeView update with hunderds of items in it):

Do
  Sleep (250)
Until MouseGetCursor () <> 15

I haven't found a better solution rather than checking mouse cursor if the cient is lagging or not :)

Works ok, but ideally I'd need it to check constantly for mouse cursor and pause script execution if mouse cursor is an hourglass, i.e. two loops running silmutaneously, the main that process Excel file and the one I've posted above.

Something like HotKeySet woule be nice, but instead of on hotkey function call, I need it to run on event when MouseGetCursor () == 15.

Here's the main portion of the code, while ProcessExcel is the function that I need to pause from time to time:

Global $is_processing = false
Global $decimal_separator = RegRead ("HKEY_CURRENT_USER\Control Panel\International", "sDecimal")

HotKeySet ("{Esc}", "Terminate")


;READ CONFIGURATION FILE
Local $config_file = @ScriptDir & "\Script.cfg"

If FileExists ($config_file) Then
  FileOpen ($config_file, 0)
  Local $client = FileReadLine ($config_file, 1)
  FileClose ($config_file)
Else
  Local $client = "Client 1"
EndIf


;CREATE GUI
Local $message
Local $gui_default_title = "Script"
Local $gui_process_title = "Processing..."

Local $gui    = GUICreate ($gui_default_title, 180, 70)
Local $radio1 = GUICtrlCreateRadio ("Client 1", 10, 10, 75, 15, 0x0300)
Local $radio2 = GUICtrlCreateRadio ("Client 2", 95, 10, 75, 15, 0x0300)
Local $launch = GUICtrlCreateButton ("Launch", 10, 35, 75, 25, 0x0001)
Local $exit   = GUICtrlCreateButton ("Exit", 95, 35, 75, 25)

If $client == "Client 1" Then GUICtrlSetState ($radio1, $GUI_CHECKED)
If $client == "Client 2" Then GUICtrlSetState ($radio2, $GUI_CHECKED)

GUISetState (@SW_SHOW, $gui)


;MAIN CYCLE
Do
  $message = GUIGetMsg ()
  $is_processing = false

  If BitAnd (GUICtrlRead ($radio1), $GUI_CHECKED) Then $client = "Client 1"
  If BitAnd (GUICtrlRead ($radio2), $GUI_CHECKED) Then $client = "Client 2"

  If $message == $launch Then
    ProcessExcel ()

    GUICtrlSetState ($radio1, $GUI_ENABLE)
    GUICtrlSetState ($radio2, $GUI_ENABLE)
    GUICtrlSetState ($launch, $GUI_ENABLE)
    GUICtrlSetState ($exit, $GUI_ENABLE)
    WinSetTitle ($gui_process_title, "", $gui_default_title)
    WinActivate ($gui)
  EndIf

  If $message == $exit Then $message = $GUI_EVENT_CLOSE
Until $message == $GUI_EVENT_CLOSE

;WRITE CONFIGURATION FILE
WriteConfigFile ()

Any ideas how this could be done?

Thanks in advance!

Edited by mjolnirmarkiv

Share this post


Link to post
Share on other sites
martin

You might need to be careful about using ablibregister if you are going to pause a script. Maybe something like this

Global $Adlibbing1 = 0

AdlibRegister("mousetest",200)

;code



func mousetest()
    if $Adlibbing1 Then return
    
    $Adlibbing1 = 1 ;<--added missing line **

    while mouseisHourGlass()
        sleep(400)
    WEnd
    
    $Adlibbing1 = 0
EndFunc

Or
func mousetest()
AdlibUnRegister("mousetest")

    while mouseisHourGlass()
        sleep(400)
    WEnd
    
AdlibRegister("mousetest",200)

EndFunc

17Nov2013- added missing line **

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
mjolnirmarkiv

Thank you, billo and martin, it's working nicely!

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  

×