How to check that the window close button is pressed [x] - autoit

$variable = MsgBox(0, "", "Return value.")
MsgBox(0, "", $variable)
; Always returns 1
Is it possible to do this in the simplest way without using
Win* functions,
Au3Info

As you are using the $MB_OK flag, the MsgBox is considered as "for info only" and Window does not distinguish between the various actions. If you look at the returns from MsgBoxes with multiple buttons, you usually find that the [X] returns the same value as the "Cancel" button.
If you really want to distinguish when the user closes the dialog with the [X], try the ExtMsgBox UDF (https://www.autoitscript.com/forum/topic/109096-extended-message-box-new-version-19-nov-21/) - that does give a unique return.

Related

How to escape from an update message?

I have following message in Progress-4GL:
DEF VAR L-temp AS CHARACTER.
MESSAGE "Give me information" UPDATE L-temp.
This shows an update message, which is fine, but when I try to escape from that message (e.g. I realise that I have clicked on the wrong button, launching this message), I can't hide that message:
How can I solve this (I simply want to remove the message from screen)?I can't add VIEW-AS ALERT-BOX as alert-boxes only can update logical variables and fields. Or is there a simple Show-Dialogbox() for such a case?
Edit
I tried replacing UPDATE by SET and viewing the whole thing as an alert-box, but this seems not to be allowed up (only logical variables and fields seem to be allowed).
Edit 2
Trying with PROMPT-FOR was not a good idea, because this seems to hide the rest of the window, while I want the message to be shown as some kind of a popup in top of the rest of my window/frame.
Edit 3
Also System-Dialog seems not to be a good idea, because all I want is to get a simple string.
It's a bit unfortunate that the 'close window' button does not by default, close the window. Even when a frame is defined as a modal dialog-box, the window-close event needs to be rerouted to close.
define frame frupdate
cinfo as char label "Give me information" with side-labels
with
title "Message Update"
view-as dialog-box
.
on "window-close" of frame frupdate
apply "close" to frame frupdate.
enable all with frame frupdate.
wait-for close of frame frupdate.

How to make a message box to close the running process?

When the process is running I need a message box with "Cancel" and "Proceed" buttons:
Cancel = stop script (exit from script).
Proceed = kill the process
to continue the script.
As Stephan said Autoit does not have built-in functionality like that.
So you have three options:
adapt your script to one of the predefined ones, such as MessageBox($MB_OKCANCEL, "", "Click 'Ok' to kill process") or more relevant but with extra button: $MB_CANCELTRYCONTINUE
use GuiCreate() to make your own message box
download and use someone else's code that does what you want, such as: Melba23's ExtMsgBox - those are called UDFs and are generally found on AutoIt forums
MsgBox() has some predefined button combinations (first parameter "Flag"):
0 OK
1 OK and Cancel
2 Abort, Retry, and Ignore
3 Yes, No, and Cancel
4 Yes and No
5 Retry and Cancel
6 Cancel, Try Again, Continue
$x = MsgBox(1, "Proceed?", "Want to continue?")
ConsoleWrite($x & #CRLF)
If $x = 1 Then ConsoleWrite("continuing..." & #CRLF)
If $x = 2 Then ConsoleWrite("exiting..." & #CRLF)
If you don't want to use them, you will have to build your own GUI instead.

catching change in spinbox - rtcltk

I'm creating a spinbox in R using rtcltk with:
from <- tkwidget(leftFrame, type="spinbox", from=0, to=0.1,
inc=0.001, textvariable=freqFrom,
command = function(){updatePlot()})
This works as intended (updatePlot is called) when I use the arrows of the spinbox, but does not work if I just type something in manually.
How do I catch the "value changed" event?
By default it does not change in this case in case you type in an illegle value (like deleting the last digit), or if the update is time consuming then you would not want it to update between every keystroke when typing in a 3 or 4 digit number.
You can add an update button than calls updatePlot when clicked so that the user would type in the number and when they know they are finished would click the button.
If you really want the update to occur with every keystroke then you can use the tkbind function to call updatePlot (something like tkbind(*spinbox*, "<Key>", updatePlot) where spinbox is the variable pointing to the spinbox).

How to get texts in ListBox using AutoIt

I am using AutoIt to create an auto-install application. There is an dialog which contains a ListBox control, and in the listbox there are some choices for user (the detailed choices depends on user's machine. For some users there maybe only one choice, for some users there may be three choices, etc.), so I want to get the texts in the listbox to make the decision. I have tried the following code, but it did not work.
; 2223 is the ID of listbox
$txt = ControlGetText("Select Web Site", "", "[ID:2223]")
Msgbox(0, "", $txt)
After execution $txt is null.
So what should I do to get the texts in Listbox?
Here is the attribute of the listbox monitored by AutoIt v3 Window Info:
Class: WindowsForms10.Listbox.app.0.33c0d9d
I've found the 'Send' command to be unreliable on occasion, particularly if the PC is locked.
'ControlSend' has always worked to get the keystrokes where I want them.
I wrote a test to check to see if an item was in a combo box. There might be similar functions for list boxes using GuiComboBox.au3.
Func DoesItemExistInComboBox($windowtitle, $windowtext, $comboboxcontrol, $itemtocheck)
$returnvalue = 0
$ComboBoxHandle = ControlGetHandle($windowtitle, $windowtext, $comboboxcontrol)
$ComboBoxArray = _GUICtrlComboBox_GetListArray($ComboBoxHandle)
For $i = 0 TO UBound($ComboBoxArray)-1
If $ComboBoxArray[$i] = $itemtocheck Then
$returnvalue = 1
EndIf
Next
return $returnvalue
EndFunc
What about:
ControlCommand("My GUI", "", "[CLASS:ListBox; INSTANCE:1]", "SelectString", "item2")
What I want to do is to select one of the items named "Default Web Site" in the list, but it seems that the list content can not be got, so finally I tried another way:
At first I make the listbox focused, and then I choose the item "Default Web Site" by sending "Def":
ControlFocus($Title, "", "[NAME:lbWebSites]")
; Select the option "Default Web Site", so press "def" to set the desired item.
Send("Def")

How do I take keyboard input in AutoIt?

I want to write a script in AutoIt, which can take automatic input from the keyboard, let's say A-Z, without user intervention.
Is this possible?
It is unlikely that your program needs to capture all input from all keys. If you do in fact need that kind of user input AutoIt might not be for you - see the post from the author of AutoIt about keyloggers. If you need to take keyboard input of the hotkey type: doing that in AutoIt is super easy.
HotKeySet("^+{q}", "reactionFunction")
While 1
; A loop
WEnd
Func reactionFunction()
MsgBox(0, "You pressed CTRL+Shift+q", "You pressed CTRL+Shift+q")
Exit
EndFunc
If you want to take user input from an input box that is really easy also.
$data = InputBox("Enter Something", "Enter some data in the field below.")
MsgBox(0, "The String You Entered...", "The string you entered is... " & $data)
More information about HotKeySet and InputBox can be found in the AutoIt.chm help file (it's actually a great reference).
Not sure I understand your question - you want to simulate keypresses without someone actually using the keyboard? If so, that's the send command in AutoIt.
You want to let a real user submit input to the script? That's what the GUI in AutoIt is for.

Resources