Jump to content

Open and focus Calculator


spuuunit
 Share

Recommended Posts

I'm doing a script that opens and focuses the calculator, or closes it if it exists. My problem is that sometimes it appears behind other windows, and sometimes it doesn't focus, and sometimes it focuses but keyboard strokes doesn't register, and sometimes everything works fine... I really can't figure out why it differs like this. I have a similar thing that brings up or minimizes foobar2000, and that always works.

 

Here's my code:

#include <Misc.au3>
#include <Sound.au3>
#include <AutoItConstants.au3>
$hDLL = DllOpen("user32.dll")
Opt("SendCapslockMode", 0)
AutoItSetOption("WinTitleMatchMode", 2)
AutoItSetOption("MouseCoordMode", 0)


While 1
    If _IsPressed("43", $hDLL) Then ; C
        If WinExists("Kalkylatorn") Then
            WinKill("Kalkylatorn")
        Else
            Run("calc.exe")
            WinSetState("Kalkylatorn", "", @SW_RESTORE)
            WinActivate("Kalkylatorn")
        EndIf
        While _IsPressed("43", $hDLL)
            Sleep(10)
        WEnd
    EndIf
    Sleep(50)
    
    
    If _IsPressed("46", $hDLL) Then ; F
        $state = WinGetState(" [foobar2000 v")
        If $state = 23 Or $state = 31 Then
            WinSetState(" [foobar2000 v", "", @SW_RESTORE)
            WinActivate(" [foobar2000 v")
        Else
            WinSetState(" [foobar2000 v", "", @SW_MINIMIZE)
            If WinActive(" [foobar2000 v") Then
                WinActivate("Program Manager")
            EndIf
        EndIf
        While _IsPressed("46", $hDLL)
            Sleep(10)
        WEnd
    EndIf
WEnd

 

Edited by spuuunit
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...