Jump to content
brodillo

Automating Calculator for windows 10

Recommended Posts

brodillo

Hello, I've experience using automation anywhere. Now I want to learn Auto It for my automatization projects.

I've tried to implement an example using calculator program in Windows 10.

When I used au3Info program to identify  an escefific zone in the calc window , au3info always return the same advanced class  [CLASS:ApplicationFrameInputSinkWindow; INSTANCE:1] 

Is there a restriction for windows 10?

See my little script

 

Run("Calc.exe")
WinWaitActive("Calculadora")
WinActive("Calculadora")

$old="0"
$new="1020"

$controlNumber="[CLASS:ApplicationFrameInputSinkWindow; INSTANCE:1]"
ControlSetText("Calculadora","",$controlNumber,$new)
ControlSend("Calculadora","",$controlNumber,$new)

 

I've tried using controlSetText and ControlSend.

 

Thank you for your help

 

Share this post


Link to post
Share on other sites
czardas

This works on Win 7. I don't know if the code helps you.

; Run the Windows Calculator.
Run("calc.exe")

; Wait for the calculator to become active with a timeout of 10 seconds.
WinWaitActive("[CLASS:CalcFrame]", "", 10)

; If the calculator did not appear after 10 seconds then exit the script.
If WinExists("[CLASS:CalcFrame]") = 0 Then Exit

; Automatically type the 123456789 into the calculator.
ControlSend("[CLASS:CalcFrame]", "","[CLASS:#32770; INSTANCE:1]", '123456789')

; Slow the script down so we can see what's going on.
Sleep(6000)

; Close the Windows calculator - always tidy up afterwards.
WinClose("[CLASS:CalcFrame]")

 

Edited by czardas

Share this post


Link to post
Share on other sites
Danyfirex

This work in windows 10.

; Run the Windows Calculator.
Run("calc.exe")

; Wait for the calculator to become active with a timeout of 10 seconds.
WinWaitActive("[CLASS:ApplicationFrameWindow]", "", 10)

; If the calculator did not appear after 10 seconds then exit the script.
If WinExists("[CLASS:ApplicationFrameWindow]") = 0 Then Exit

; Automatically type the 123456789 into the calculator.
ControlSend("[CLASS:ApplicationFrameWindow]", "","Windows.UI.Core.CoreWindow1", '123456789')

; Slow the script down so we can see what's going on.
Sleep(6000)

; Close the Windows calculator - always tidy up afterwards.
WinClose("[CLASS:ApplicationFrameWindow]")

Saludos

Share this post


Link to post
Share on other sites
1905russell

Danyfirex's script is very cool.

Remember I’m an accountant not a programmer and its tax-time and this is distracting me.

Using Danyfirex's script above, how do I ControlSend an operator like “+” or “-“  without it being ignored?

Also, I want to read the result value displayed, without using OCR. Is it possible?

ControlGetText returns “Calculator” (same as visible text, using AWI)

Am I asking too much? 

 

Edited by 1905russell

Share this post


Link to post
Share on other sites
Danyfirex

Hello you can do something like this:

Opt("SendKeyDownDelay",20)

; Run the Windows Calculator.
Run("calc.exe")

; Wait for the calculator to become active with a timeout of 10 seconds.
WinWaitActive("[CLASS:ApplicationFrameWindow]", "", 10)
Sleep(1000)

; If the calculator did not appear after 10 seconds then exit the script.
If WinExists("[CLASS:ApplicationFrameWindow]") = 0 Then Exit

; Automatically type the 123456789 into the calculator.
ControlSend("[CLASS:ApplicationFrameWindow]", "","Windows.UI.Core.CoreWindow1", '123456789')
Sleep(500)
; Send + symbol
ControlSend("[CLASS:ApplicationFrameWindow]", "","Windows.UI.Core.CoreWindow1", '+',1) ;1 means send raw key
Sleep(500)
; Automatically type the 123456789 into the calculator.
ControlSend("[CLASS:ApplicationFrameWindow]", "","Windows.UI.Core.CoreWindow1", '123456789')
Sleep(500)
;send enter to calc
ControlSend("[CLASS:ApplicationFrameWindow]", "","Windows.UI.Core.CoreWindow1", '{ENTER}')
Sleep(500)
; just for making sure the windows is active to send ctrl+c to copy the result to clipboard
WinActivate("[CLASS:ApplicationFrameWindow]")
Send("^c")


MsgBox(0,"","Result: " & ClipGet())

To get a better result I prefer to use UIAutomation UDF.

 

Saludos

Share this post


Link to post
Share on other sites
alienclone

do you specifically need to use the windows 10 built-in calculator program? if not, searching the forum should bring up some user created calculator guis that are automation friendly.


if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah yeah, patience. How long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites
1905russell

@Danyfirex thanks for replying so quickly and for the enhanced script but both the '+' and '{Enter}' are still not recognized. Does this work for you?

I'm using Calculator Version 10.1803.711.1000
I'm going to fiddle with this script because it should work?

@alienclone Yep, I know the are Autoit calculators on the forums but this one every Windows user already has and it's very sophisticated and if Autoit can manipulate it then there is much potential to expand its use.   

Edited by 1905russell

Share this post


Link to post
Share on other sites
Earthshine

i doubt you will find a solution using just AutoIt proper. However, FAQ 31 has more complete answers.

IUIAutomation can help you with XAML applications like Calc in Windows 10

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
1905russell

@junkew - Exactly,  to demonstrate concepts of (data collection and) automation. I have a patented system that needs demonstrating in all its forms.  Calc looked like another way to display the system because it has a pseudo tape which is what I was looking for.

I figured that using MS calc.exe would allow me the same manipulating privileges as notepad and other MS utilities. I guessed wrong.

I've discovered when using MScalc that ControlSend:

‘-‘ sends ‘-‘

‘/’ sends ‘/’

‘=’sends ‘=’

‘+’ sends ‘=’

‘*’ sends 8

I looped all the ASCII codes and observed that none pushed the "+" button.

This is strange because the physical keystroke "+" sends "+"  

I can always calculate the approximate location of the "+" button and push it that way.  

I'm in the middle of tax-time and will get back to this when I can or when its over (Canada April30). 

Thanks for the feedback everyone.

Share this post


Link to post
Share on other sites
Earthshine

XAML forms Do not work with standard auto IT


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
1905russell

@Eathshine and @junkew - will definitely look at all that and I'm looking forward to it, once all tax returns are completed.

Share this post


Link to post
Share on other sites
Earthshine
On 4/12/2018 at 3:36 PM, 1905russell said:

@Eathshine and @junkew - will definitely look at all that and I'm looking forward to it, once all tax returns are completed.

hey, if you need a test harness, I use Appium with C# (but it's language agnostic, choose your poison) to test all our products. Their example uses Calc. Look how easy it is to start manipulating anything UIA accessible

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Remote;

namespace SomeAppTests
{
    [TestClass]
    public class SomeAppTester
    {
        protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723/wd/hub";
        protected static RemoteWebDriver SomeSession;
        protected static RemoteWebElement SomeResult;

        [ClassInitialize]
        public static void Setup(TestContext context)
        {
            // Launch the Iccp Configuration application
            DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("app", "D:\\Program Files (x86)\\Company Name\\Configuration Tools\\SomeApp.exe");
            appCapabilities.SetCapability("platformName", "Windows");
            appCapabilities.SetCapability("deviceName", "WindowsPC");
            SomeSession = new RemoteWebDriver(new Uri(WindowsApplicationDriverUrl), appCapabilities);
            Assert.IsNotNull(SomeSession);
        }

 
        [TestMethod]
        public void TestMethod1()
        {
            SomeSession.FindElementByName("View").Click();
            SomeSession.FindElementByName("Restore Default Size").Click();
            SomeSession.FindElementByName("Tools").Click();
            SomeSession.FindElementByName("Start Log Viewer...").Click();
        }
    }
}

and it is lightning fast, wraps the UIA stuff for you, you can find by almost anything used, ID, XPath, etc... child's play. Requires Windows 10/Server 2016 in Debug Mode with the free WinAppDriver installed and Appium. All free except the OS. It can test any Win32, WinFoms, WPF, etc.. (it can also fully test iOS and Andriod apps if you care or produce products). You could author in free tools, such as Visual Code (and use any test runners you want, it will execute all the test methods decorated with [TestMethod], MSTest is what I like, but you can use XUnit, NUnit, whatever). I use .NET Core Unit Test  projects.

Here is the Calculator test in Win10

 

 

BasicScenarios.cs

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
DynamicRookie

Hola!

 

Tambien puedes usar el comando Send() para automatizar una calculadora de forma sencilla activando la ventana.

 

Usa el comando WinActive para sacar el Handle of Window (HWnd) de la ventana de la calculadora, y luego experimenta con otros comandos.

 

Puedes mandarme mensaje directo si tienes algun otro inconveniente

 

Saludos!

Share this post


Link to post
Share on other sites
Earthshine

so, @DynamicRookie, can you show me your script in standard autoit that can fully manipulate Windows 10 Calculator.exe or any other WPF application? I would be interested.


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
DynamicRookie
2 hours ago, Earthshine said:

so, @DynamicRookie, can you show me your script in standard autoit that can fully manipulate Windows 10 Calculator.exe or any other WPF application? I would be interested.

Didn't make one, i deduced the person that posted the question is spanish according to the "Calculadora" in his code, so gave him some tips to automate one easier.
However i could make one easily in a few hours 

Share this post


Link to post
Share on other sites
junkew

@DynamicRookie The interesting question would be how you do that in W10 when AU3Inf is not recognizing the controls.
You only can do it with the IUIAutomation library which details can be found thru FAQ31.

So I assume @Earthshine (just like me) is interested how you would do it with native commands from AutoIt? The only thing I can quess you are saying is to use only sendkeys and not automating the clicks on the buttons itself which is basically the same as answerd in post 2 with controlsend.

 

Edited by junkew
  • Like 1

Share this post


Link to post
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

  • Similar Content

    • antonioj84
      By antonioj84
      Hi all to the forum guru and expert I am trying to  automate this. in the registry  I have the network profile name network 2 and network   I want to  change their  CATEGORY  to Private .  Can someone lead me in the right direction.
      Private is 1 and Public is 0
      #RequireAdmin Global $sHKLMRoot = @OSArch = "x64" ? "HKLM64" : "HKLM" RegWrite($sHKLMRoot &"\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\NewNetworks" ,'/v NetworkList /t REG_MULTI_SZ /d 00000000 /f') see  attached picture below
      Much appreaciate
       

    • PhoenixPRO
      By PhoenixPRO
      When I try to automate this install program I can not get any of the buttons to click with the "ControlClick" function or any mouse movement to move the mouse to the and click it.  My OS is Windows 10 64Bit.  I have tried both 32bit and 64bit installs of Autoit V3 to no avail.
      I could not even get the run command to start the program until I used the variation of the command below in the script.
      With the script below the install program starts but will not click the "Next" button no matter what I do.
      Any help will be greatly appreciated.
      Thanks in advance.
       
      #include <MsgBoxConstants.au3>
      Opt("MouseCoordMode", 0) ;1=absolute, 0=relative to active window, 2=client
      Local $Success
      Run(@ComSpec & " /c " & 'C:\PhoenixPro_Install\RDXUtil\RDX_Tools_setup.exe', "C:\PhoenixPro_Install\RDXUtil", @SW_HIDE )

      WinWait("RDX Tools 1.62 - InstallShield Wizard", "Welcome to the InstallShield Wizard for RDX Tools 1.62")
      WinActivate("RDX Tools 1.62 - InstallShield Wizard", "Welcome to the InstallShield Wizard for RDX Tools 1.62")
      ControlClick ("RDX Tools 1.62 - InstallShield Wizard", "Welcome to the InstallShield Wizard for RDX Tools 1.62", 1639, "left", 1) ;Next Button
    • TheWizEd
      By TheWizEd
      How do I work with 2D arrays.  I've tried this but get errors.
      Local $aTest[4][4] = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
      ;$aTest[0][] = [10,11,12]  ; Error at []
      Local $sTest = ""
      For $i = 0 To UBound($aTest)-1
        Local $aExtract = _ArrayExtract($aTest,$i,$i)
        $sTest = $sTest & MyTest($aExtract)
      Next
      Func MyTest($aTemp)
        _ArrayDisplay($aTemp)
        ; Error at    v $aTemp
        Return String($aTemp[0]) & " - " & String($aTemp[1]) & " - " & String($aTemp[2]) & @CRLF
      EndFunc
       
       
    • AndyK70
      By AndyK70
      I'm trying to fill a ListView with all normal viewable windows to act with them.
      First I tried with WinList:
      Local $aWinList = WinList("[REGEXPTITLE:(?i)(.+)]") Local $aTmp, $iID ;~ _ArrayDisplay($aWinList) For $i = $aWinList[0][0] To 1 Step -1 ; going backwards not disturbing the index while cycling through and deleting some If StringStripWS( $aWinList[$i][0], 3) == "" Or _ Not BitAND(WinGetState($aWinList[$i][1]), $WIN_STATE_VISIBLE) Or _ BitAND(WinGetState($aWinList[$i][1]), $WIN_STATE_MINIMIZED ) Then _ArrayDelete($aWinList, $i) Else ; Window has a Title and is "visible" $aTmp = WinGetPos($aWinList[$i][1]) If $aTmp[0] < -1000 Or $aTmp[1] < -1000 Then ; Window is minimized or tray icon _ArrayDelete($aWinList, $i) EndIf EndIf Next $aWinList[0][0] = UBound($aWinList)-1 ; getting actual # of windows ; Each row is now [ID]=> [Title], [hWnd] But it keeps getting Windows which are definitely not there at least not visible:

      Those windows "Rechner", "Einstellungen", "Netflix", "Microsoft Store", ... are not there!?! 
      It should list only the first three windows, which are real.
      I even tried it with _WinAPI_ UDF:
      $hWnd = _WinAPI_GetForegroundWindow() ; Add items _GUICtrlListView_BeginUpdate($idListview) If $hWnd <> 0 Then $iI = 0 Do If _WinAPI_IsWindow($hWnd) And _WinAPI_IsWindowVisible Then _GUICtrlListView_AddItem($idListview, WinGetTitle($hWnd)) _GUICtrlListView_AddSubItem($idListview, $iI, $hWnd, 1) $iI += 1 $hWnd = _WinAPI_GetWindow($hWnd, $GW_HWNDNEXT) EndIf Until $hWnd = 0 EndIf But it is the same...
       
      How can i distinguish those invisible windows from normal ones?
      PS: I'm using Windows 10, maybe it is important to know?
    • davidacrozier
      By davidacrozier
      Hello all ~
      I am running an autoit script on Windows 10 inside VMware Workstation 12 Pro version 12.5.2.  Technically I am remoting into ESXi which has a Domain Controller (DC), WebServer, FilServer, Windows 10, etc.  Using the GUI (i.e. running explorer.exe) I am able to open several different folders successfully.  The desktop, documents, USB external all open without issue.  The network share opening gives me issues.  Whenever I attempt to open \\filserver\users\user\sharedfolder I get the documents folder instead.  I understand that the documents folder is the default for explorer.  I have also attempted to use the letter drive mapped to the network share (Z:) and receive the same result.  When I run this script on Windows 10 alone without  the VM or the ESXi I am able to open the network share without problems.  I have tried to use the net use command to designate a letter M: to the network share folder prior to running the script.  This did not work for me.  
      One additional avenue I think might work is to use the systreeview321 and _GUICtrlTreeView_FindItem to step through the tree looking for the network share.  Once found,  double click on it and see if that opens the shared network folder.  I can click inside the VM with my mouse on the network share and it opens just fine.  Not sure if running up against GUI issues, or permission issues, or what?
      Thanks in advance,
      Davida Crozier
      TestNetworkShare.au3
      This script is a subset of a much larger program, but it illustrates what I am dealing with.

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.