Jump to content

Automating Calculator for windows 10


Recommended Posts

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 10 months later...

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

@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
Link to comment
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
 Share

×
×
  • Create New...