How do I take keyboard input in AutoIt? - 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.

Related

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

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

How do I get input from the console in Nim?

I'm new to Nim, but it appears that there is no way to get input from the console in a similar way to input() in python or Console.ReadLine() in dotnet.
I want execution of my code to pause, wait for input, then on pressing enter to continue (just like input in other langs).
Oh no never mind found it:
var consoleInput = readLine(stdin);

python script more than one function

If your python script contains two or more functionalities, how can you run the script continuously to allow the user to select any one of these functionalities without restarting your program in a new IDLE console?
You could ask the user for input with the input prompt and decide what to do based on the input like this:
response = input("Please enter your name: ")
if (response == "John"):
fun_1(something)
else:
fun_2(something_else)
The input prompt will wait for user input and record every input up to a carriage return (ENTER).

Verify for text on windows application from AutoIT

I have a automating a Windows application using AutoIT tool.
I have done the scripting now I need a command by which I can verify that the particular text on the application?
For eg: I open the application,
then I execute the some task.
Once task is compelete success is displayed on the application screen.
I want to verify wheather success was displayed when task was completed.
Let me know how this can be done through AutoIT
that depends alot how the application is designed. with autoit for most windows-based uis, you can use the autoit window info tool to inspect elements, then with that info, get the control's text or value with
controlGetText [1]
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Run Notepad
Run("notepad.exe")
; Wait 10 seconds for the Notepad window to appear.
Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
; Set the edit control in Notepad with some text. The handle returned by WinWait is used for the "title" parameter of ControlSetText.
ControlSetText($hWnd, "", "Edit1", "This is some text")
; Retrieve the text of the edit control in Notepad. The handle returned by WinWait is used for the "title" parameter of ControlGetText.
Local $sText = ControlGetText($hWnd, "", "Edit1")
; Display the text of the edit control.
MsgBox($MB_SYSTEMMODAL, "", "The text in Edit1 is: " & $sText)
; Close the Notepad window using the handle returned by WinWait.
WinClose($hWnd)
EndFunc ;==>Example
Start with that and let me know if you need more help!
[1] https://www.autoitscript.com/autoit3/docs/functions/ControlGetText.htm

Focus change on control Autoit

I have a application window with two text fields (no access to the application code, so cant change anything). User scans a barcode in the fields, the action "enter press" is programmed in the scanner and cannot be changed. I need to validate the fields before enter is pressed, I can validate the first field but the issue is I need to validate the second field before enter is press(which is through the scanner). Is there a way this can be achieved using AutoIT? I hope the question make sense.
Use the "AutoIt v2 Window Info" tool (Au3Info.exe) to identify the two edit controls. On the "Control" tab you find the "Advanced Mode", which will show data like "[CLASS:Edit;INSTANCE:2]". Now use this information to read the data of the control:
$Text1 = ControlGetText('window title', '', '[CLASS:Edit; INSTANCE:1]')
$Text2 = ControlGetText('window title', '', '[CLASS:Edit; INSTANCE:2]')
See the example here: http://www.autoitscript.com/autoit3/docs/functions/ControlGetText.htm
most barcode scanners can be programmed to not send the terminator (enter) usually by scanning a couple special barcodes in the users manual
I program scanners with special terminators so our program can tell the input was from a scanner and not key presses

Resources