0
votes

I want my script to read a textfile containing an intiger and to write this number by keyboard with out me actually touching it, but im kinda having trouble understanding the autohotkey since there is no software for it. Having some C# knowledge this is what i have:

FileRead, OutputVar, answertext.txt
sleep, 3000
;MyString = %OutputVar%
MyString = 16807

Loop, Parse, MyString

{

if (%A_LoopField% = -) 
{
Send, {SC00C}
}

if (%A_LoopField% = 0) 
{
Send, {SC00B}
}

if (%A_LoopField% = 1) 
{
Send, {SC002}
}

if (%A_LoopField% = 2) 
{
Send, {SC003}
}

if (%A_LoopField% = 3) 
{
Send, {SC004}
}

if (%A_LoopField% = 4) 
{
Send, {SC005}
}

if (%A_LoopField% = 5) 
{
Send, {SC006}
}

if (%A_LoopField% = 6) 
{
Send, {SC007}
}

if (%A_LoopField% = 7) 
{
Send, {SC008}
}

if (%A_LoopField% = 8) 
{
Send, {SC009}
}

if (%A_LoopField% = 9) 
{
Send, {SC00A}
}
}  
exit

Now this code starts but it always punches in 0 and nothing else, and if MyString = -1234, there is an error.

1
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your code and accurately describe the problem. Specifically, you need to supply the full error output and compare it to the expected action. Also reduce this to the minimum needed to reproduce the problem.Prune
As said above, please try to describe your root problem first (why are you doing this, what are you trying to solve with your solution) before concentrating on the problem you encounter with your chosen strategy. (Google X Y Problem). Always willing to help though!Robert Ilbrink
The code looks immensely and needlessly overcomplicated. Why not simply Send %MyString%, why are you sending the hardware scancodes?wOxxOm

1 Answers

0
votes

I will provide here some notes on improving your AutoHotkey script, and an amended version of it.

Your 'if' lines should be like this for most strings, with double quotes, and no percent signs:

if (A_LoopField = "a")

With numbers the double quotes are optional:

if (A_LoopField = "1")

if (A_LoopField = 1)

However fundamentally, your script need only be a few lines long:

FileRead, OutputVar, answertext.txt
sleep, 3000
;MyString = %OutputVar%
MyString = 16807
Send {Raw}%MyString%

You may prefer to include a key delay, to slow down the sending of text:

MyString = 16807
SetKeyDelay, 500
Send {Raw}%MyString%

Other methods for sending the text might be:

Clipboard := MyString
SendInput ^v

Or to insert text into Edit controls such as in Notepad for example without using the clipboard:

Control, EditPaste, %MyString%, Edit1, ahk_class Notepad

Or to set the entire contents of Edit controls, again without using the clipboard:

ControlSetText, Edit1, %vText%, ahk_class Notepad