Jump to content
brodillo

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

 

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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

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

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

@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

Why would you automate windows calculator except for demonstrating the concepts of automation?

Excel is much easier to calculate or just a powershell commandline to do your calculations without any troubles in object recognition.

Share this post


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

Share this post


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

 

Share this post


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

Share this post


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

Share this post


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

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

    • By gahhon
      I have a application that have a function is to create a shortcut to desktop, lets say is ChromePortable.lnk.
      $iCreate = FileCreateShortcut($DIR_WA_FOLDER & '\GoogleChromePortable.exe', $DIR_SHORTCUT, $DIR_WA_FOLDER, '--kiosk "https://example.com/"') So the shortcut will be launch as kiosk mode and force to enter the specific website. However, the user is still able to right-click on the shortcut and modify the target value to remove the kiosk mode. What can I do to disable the user to editing the target value?
      So far, I had asked and tried from SuperUser for advises Disable Shortcut Target Field
      icacls "ChromePortable.lnk" /GRANT EVERYONE:RX So this will set the permission of this shortcut file to only Read & Execute only! But after I set it, the user is still can modify.
      Please kindly advise.
      Please note and assume that user don't have Administration account or etc, that should be only have 1 account to logon to the computer.
       
      EDIT:
      I must disable inheritance to remove all others permissions like SYSTEM, ADMINISTRATORS, etc. Then only GRANT everyone for READ & EXECUTE only.
      But still the user can go to edit the permissions tho. Any advise?
    • By ur
      When I compiled my script or any script to exe using 32 bit compiler and ran on 32 bit machine, I am getting below error.
       

       
      But it is 32 bit only.
       
      And, for testing, I disabled smart screen also, but same issue.
      Please suggest.
       
    • By sadakathullah
      Hi All, I am new to AutoIT and exploring options to use it in my organization. I tried couple of examples and it is fantastic. I am trying to run restrictions test in a pc to see if certain options are disabled like print screen, mstsc etc. I could not get a hang of it. Any help is much appreciated.
    • By stayready40
      Hello all. I created a script to uninstall Symantec from our environment and I placed the "BlockInput(1)" command in the beginning of the script so that end users would not be able to move the mouse or keyboard to disrupt the mouse clicks.
      During testing we found that this worked for our Windows 7 machines, but for our windows 10 machines the mouse disable did not work can anyone shed some light on why this is? 
      Here is my code:

       
    • By faustf
      hi guys
      i have a script  like this,  in windows 7 work perfect , in windows 10 not  work  , some one can explain me  why ??'
      #include <Array.au3> #include <MsgBoxConstants.au3> Global $aGPathFoto= FileReadToArray (@ScriptDir & "\TEMP\PathFoto.txt") Local $ctrl = 0 While 1 Local $hWnd = WinWait("[CLASS:#32770]", "", 10) If WinExists("[CLASS:#32770]") Then If $ctrl < 2 Then ControlSend($hWnd, "Choose File to Upload", "[CLASS:Edit; INSTANCE:1]", $aGPathFoto[0]&"{Enter}") Exit $ctrl += 1 Else ExitLoop EndIf EndIf WEnd $aGpathfoto = C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg
×
×
  • Create New...