if winexist winactivate else run problem Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xurm
Posts: 2
Joined: 01 Apr 2023, 15:43

if winexist winactivate else run problem

Post by xurm » 01 Apr 2023, 16:12

I've been trying this out for the last 2 days, al my hotkeys etc works, even the xButton2, but my Xbutton1 does not. i've tried anything including the full path to the calc.exe as you can see but still nothing. i tested with a simplewinclose command and that worked, so i'm sure my button is working as intended, it's just the damn code i'm not familiar with. I tried also adding brackets and removing them.
So, if i'm in autocad, and i click the xbutton2, it just either set the focus on the calculator, or, if it's not open, it should.

"Rekenmachine" is dutch for calculator, and is the name of the window:
from window spy:
Rekenmachine
ahk_class ApplicationFrameWindow
ahk_exe ApplicationFrameHost.exe
ahk_pid 10360
ahk_id 659352

Code: Select all

#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
SetTitleMatchMode Fast
#WinActivateForce
SetControlDelay 1
SetWinDelay -1
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1

#if WinActive("ahk_exe acad.exe")
XButton2::
Send, {u}
Sleep, 15
Send, {c}
Sleep, 15
Send, {s}
Sleep, 15
Send, {Space}
Return

XButton1::
If (WinExist ("Rekenmachine"))
{
   WinActivate ("Rekenmachine")
}   
Else
{
	Run, "C:\Windows\WinSxS\wow64_microsoft-windows-calc_31bf3856ad364e35_10.0.19041.1_none_6a03b910ee7a4073\Calc.exe"
}
Return

#If
[Mod edit: Moved topic to v1 help, based on posted code.]

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: if winexist winactivate else run problem  Topic is solved

Post by mikeyww » 01 Apr 2023, 17:23

Welcome to this AutoHotkey forum!

Function names are always followed by (, not a space. For examples, have a look at the documentation, some posted scripts, or line 15 of your script.

When you are unsure of the value returned by your function, you can use the script to display it.

xurm
Posts: 2
Joined: 01 Apr 2023, 15:43

Re: if winexist winactivate else run problem

Post by xurm » 02 Apr 2023, 09:30

Erghh, thank you mikey.
This was literally a PEBCAK (Problem Exists Between Chair And Keyboard)
I was looking way to far with all the brackets and etc.I decided to start a whole new script just to test/rewrite and basicly it's this simple:

Code: Select all

XButton1::
If WinExist("Rekenmachine")
  WinActivate
   
else
	Run, calc.exe
	
Return
It did'nt worked at first, but after reading your comment and deleteting the space bewteen winexist and ("Rekenmachine"), it works fine now.
Thank you again Mikey, cudos :bravo: :dance: :clap:

Post Reply

Return to “Ask for Help (v1)”