Jump to content

Use GUI Pic Clicked like HotKeySet?


IAMK
 Share

Recommended Posts

This is a fairly simply script, but the feel of it is terrible.

Currently, the script has an infinite file loop with a 1-second sleep. Each time, it will check if the picture on my GUI has been clicked or not. However, this is not good, especially if clicked multiple times, as I need the if statement to happen ASAP, not after a possible 1-second sleep.

$pic = GUICtrlCreatePic("image.jpg", 0, 0, 100, 35) ;Just for reference for below.

While(1)
   $msg = GUIGetMsg()

   If $msg = $pic Then
      Send("Hello")
   EndIf

   Sleep(1000)
WEnd

I can't seem to find a way to use GUI Pic clicks as an event like HotKeySet. E.g.

HotKeySet("{DEL}", "endScript")

 

Thank you in advance.

Edited by IAMK
Link to comment
Share on other sites

I'm not sure I understand the issue. Just take out the sleep. This is how most GUI scripts work anyway.

#include <GUIConstants.au3>

$hGUI = GUICreate('GUI')
$pic = GUICtrlCreatePic('image.jpg', 0, 0, 100, 35)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $pic
            endScript()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func endScript()
    Exit ; ?
EndFunc

 

Edited by therks
Link to comment
Share on other sites

  • Developers

There should never be a sleep() statement in a close message loop.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Jos, If there is no sleep, then it will cycle through 100000x really quickly, eating up my CPU/performance. I need this to run alongside other scripts + my company's project (which needs to be performing at normal visual speeds). No lag/stutter should be observed.

Also, the label can be pressed more than once, so I'm not just polling until it's pressed then running a script.

Link to comment
Share on other sites

  • Developers

Nope, the GuiGetMsg() has an build in 10 ms delay and making that more will cause all kinds of issues with capturing the messages from the gui!

So removing the sleep() will not cause a close loop without a pause.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Jos, Even then, I believe it may be an issue in a more complex script. For this simple script, it is fine. My project needs to remain 60fps.
It's fine. I guess this can't be done the same way as a hotkey which can be called from anywhere.

Thanks.

Link to comment
Share on other sites

  • Developers

It is a problem when you introduce the sleep() in the close message loop so you need to come up with the logic that it also works for you without intoducing the sleep(), not the other way around!

5 hours ago, IAMK said:

My project needs to remain 60fps

I have no idea what that means other than you want 60 frames per second for something. I would say try usimg AdlibRegister() for braking out of the regular loop at that interval to perform a Func.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

1 hour ago, Jos said:

I have no idea what that means other than you want 60 frames per second for something.

My company's projects are animation-based, so the visuals should look normal/smooth while my scripts run.

I like the Adlib function, thanks. I will use it for other things :)

Edited by IAMK
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...