I'm trying to build an automatic answer for a simple math question where the number of total variables in the question depends on the position of the question mark, here are few examples:
What is 56 x 3 ?
What is 7 x 3 ?
What is 232 x 634 ?
I have created a code but I can't make it work, here is my code
#include <AutoItConstants.au3>
HotKeySet("{F4}", "ExitProg")
Func ExitProg()
Exit 0
EndFunc
MouseClick($MOUSE_CLICK_LEFT, 417, 659, 2, 1)
Send("^c")
Func valData()
$Chek = "What "
If ClipGet() == $Chek Then
Check()
Else
Do
MouseClick($MOUSE_CLICK_LEFT, 417, 659, 2, 3)
Send("^c")
Sleep(500)
Until ClipGet() == $Chek
EndIf
EndFunc
Func Check()
$Chek2 = "?"
Select
Case c1() == $Chek2
;two
cc1()
Case c2() == $Chek2
;three
cc2()
Case c3() == $Chek2
;four
cc3()
Case c4() == $Chek2
;five
cc4()
Case c5() == $Chek2
;six
cc5()
Case c6() == $Chek2
;seven
cc6()
Case c7() == $Chek2
;eight
cc7()
Case Else
Exit
EndSelect
EndFunc
Func c1()
MouseClick($MOUSE_CLICK_LEFT, 485, 643, 2, 1)
Send("^c")
EndFunc
Func c2()
MouseClick($MOUSE_CLICK_LEFT, 493, 644, 2, 1)
Send("^c")
EndFunc
Func c3()
MouseClick($MOUSE_CLICK_LEFT, 498, 645, 2, 1)
Send("^c")
EndFunc
Func c4()
MouseClick($MOUSE_CLICK_LEFT, 508, 647, 2, 1)
Send("^c")
EndFunc
Func c5()
MouseClick($MOUSE_CLICK_LEFT, 514, 645, 2, 1)
Send("^c")
EndFunc
Func c6()
MouseClick($MOUSE_CLICK_LEFT, 523, 645, 2, 1)
Send("^c")
EndFunc
Func c7()
MouseClick($MOUSE_CLICK_LEFT, 530, 645, 2, 1)
Send("^c")
EndFunc
Func cc1()
MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("^v")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 474, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("*")
Send("^v")
Send("{NUMPADENTER}")
EndFunc
Func cc2()
MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("^v")
SLeep(500)
MouseClick($MOUSE_CLICK_LEFT, 482, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("*")
Send("^v")
Send("{NUMPADENTER}")
EndFunc
Func cc3()
MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("^v")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 487, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("*")
Send("^v")
Send("{NUMPADENTER}")
EndFunc
Func cc4()
MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("^v")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 495, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("*")
Send("^v")
Send("{NUMPADENTER}")
EndFunc
Func cc5()
MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("^v")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 495, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("*")
Send("^v")
Send("{NUMPADENTER}")
EndFunc
Func cc6()
MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("^v")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 509, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("*")
Send("^v")
Send("{NUMPADENTER}")
EndFunc
Func cc7()
MouseClick($MOUSE_CLICK_LEFT, 453, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("^v")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 509, 645, 2, 1)
Send("^c")
Sleep(500)
MouseClick($MOUSE_CLICK_LEFT, 1347, 197, 1, 1)
Send("*")
Send("^v")
Send("{NUMPADENTER}")
EndFunc
valData()
MouseClick($MOUSE_CLICK_LEFT, 1349, 196, 1, 1) ;clicking the answer in calc
Send("^c")
Send("{DEL}")
MouseClick($MOUSE_CLICK_LEFT, 499, 706, 1, 1)
Send("^v")
Exit
Please help me! the output of this one is only searching for the question mark and after that is not doing anything.
This is basically the same answer as user4157124
already gave. I just broke it down to a one-liner (sacrifying the error handling; if the question doesn't match the given format, $x
will be empty anyway).
ClipPut("What is 14 x 36 ?")
$x = Execute(StringRegExpReplace(ClipGet(), '^What is (\d*) x (\d*) \?$', "$1*$2"))
ConsoleWrite($x & @CRLF)
Also the REGEX Pattern [^\d]*(\d+)[^\d]+(\d+).*
works (even more reliable in case there are stray spaces in or around the question)
(There is a more elegant way to get the question with GUICtrlRead()
, but the implemention depends on how exactly the source program is built)
EDIT (just for troubleshooting):
As I can't see your screen, please run the following for troubleshooting:
MouseClick("Primary", 479, 802, 3, 10) ; slowed down to verify that the cursor goes to the right position
Send("^c")
$x = ClipGet()
ConsoleWrite('Whole question: "' & $x & '"' & @CRLF)
$x = StringRegExpReplace(ClipGet(), 'What is (\d*) x (\d*) \?$', "$1*$2")
ConsoleWrite('Math part: "' & $x & '"' & @CRLF)
$x = Execute($x)
ConsoleWrite('Result: "' & $x & '"' & @CRLF)
; MouseClick("Primary", 480, 844, 1, 1)
; Send($x)
Please report back the exact output from the console, so I can see, where things start to go wrong.