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
Posted (edited)

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 patience, how long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites
1905russell
Posted (edited)

@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
Posted (edited)

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
Posted (edited)
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
Posted (edited)

@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

    • Daydreamer067
      By Daydreamer067
      Hi
      in windows 10 i create a new desktop.
      I want to run a script in this desktop, for exemple Mouseclick("left",x,y)
      I want the script to work in that desktop while i switch to the primary desktop.
      So far autoit clicks on the active desktop.
      Is there a way to make it run only on the other desktop ?
       
      Thank you for your response.
    • codingislife
      By codingislife
      Hi everyone, 
      I'm new to the autoit world and am trying to do something a little complicated and am having trouble developing a solution. My OS after reimaging comes up with two operating system choices during boot up, I'd like to delete the incorrect OS. I have noticed that the default OS is always the correct OS. My issue is I need a way to find the OS identifier before I can delete. I know that I  can use bcdedit to find this but it changes every time and it needs to be the correct identifier (i.e. not the Default or bootmgr). If someone knows of a way to parse through the output of bcdedit to find the identifier that would be greatly appreciated. Here is an example of what I am trying to do:
      https://scottiestech.info/2016/07/03/remove-the-choose-an-operating-system-message-when-starting-your-computer/
    • PramodR
      By PramodR
      Hello,
      i am new to AUTO IT development , I would like one help to read value from a POP up.
      i am able to read below values using inspect tool , information given below, I tried to create a script to read value but that does not help. any help is appreciated.
      Available Controls
      POPUP window Controls
      Auto Id = "UpdateNow_Btn"
      Name = Update Now
      Invoke - Button Control
      Below Controls i get when i move inspector tool to the text which i need to read. i need to read the text Name . Currently with my code i get only blank text 
      Auto Id = timeOutLb
      ClassName = TextBlock
      LegacyIAccess = GetName
      Name  = Read Value for Name
       
      My code.
       
    • Dreamfire
      By Dreamfire
      Hi,
      Since today, exe's are being flagged as having a trojan by Windows Defender (Fuery.B!cl)
      Version:  3.3.14.3 - SciTE Version 3.7.3



       

    • PramodR
      By PramodR
      Hello,
      I have to execute below block of code in elevated previllage, as that particular wmic class will work only with admin previlage.
      i am getting out put when i launch autoit as administrator,  but i will not be able to launch autoit as admin in this particular case but my user have admin rights.
      is there any better way i can run those command as administrator.?
      tried below steps:
      i have tried #RequireAdmin but that creates a user prompt  Tried using Runas command but gives error as wrong username or password , stuck with that step.  
       
×