Small code to run Calc

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
w64bit
Posts: 16
Joined: 08 Aug 2018, 08:30

Small code to run Calc

08 Aug 2018, 08:40

Hello,
I am trying to write a code to open a exe file (Calculator) when press Insert key.
The code it's working when using 1.1 for converting to EXE, but not with 2.0.
I want:
1. to use 2.0
2. that the Calculator window to be on top after press Insert (maybe using WinMoveTop).
Thank you

Code: Select all

Insert::
#SingleInstance force
if WinExist("Calculator")
    WinActivate
else
    Run "C:\Program Files\Calculator\Calculator.exe"
return
Last edited by w64bit on 12 Aug 2018, 08:45, edited 1 time in total.
User avatar
Scr1pter
Posts: 1278
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Small code

08 Aug 2018, 09:12

Question:
Why do you want to use v2?
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
w64bit
Posts: 16
Joined: 08 Aug 2018, 08:30

Re: Small code

08 Aug 2018, 09:16

I think because it's new and the future changes will be smaller comparing to 1.1.
Maybe I am wrong.
Please advise.
Thank you.
w64bit
Posts: 16
Joined: 08 Aug 2018, 08:30

Re: Small code

08 Aug 2018, 15:49

No one?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Small code

08 Aug 2018, 16:01

- Does the ahk to exe converter handle AHK v2?
- Perhaps:

Code: Select all

;this:
    Run "C:\Program Files\Calculator\Calculator.exe"
;should be this:
    Run "`"C:\Program Files\Calculator\Calculator.exe`""
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
w64bit
Posts: 16
Joined: 08 Aug 2018, 08:30

Re: Small code

08 Aug 2018, 16:27

Nope.
Ok. Let's forget v2.
In v1 is there any command to put just opened window on top?
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Small code

08 Aug 2018, 20:06

w64bit wrote:Hello,
I am trying to write a code to open a exe file (Calculator) when press Insert key.
The code it's working when using 1.1 for converting to EXE, but not with 2.0.
I want:
1. to use 2.0
2. that the Calculator window to be on top after press Insert (maybe using WinMoveTop).
Thank you

Code: Select all

Insert::
#SingleInstance force
if WinExist("Calculator")
    WinActivate
else
    Run "C:\Program Files\Calculator\Calculator.exe"
return
Here is the calculator script that I use.

Code: Select all

#numpad0::	; <-- Open/Activate/Minimize Windows Calculator
{
	if WinExist("Calculator ahk_class CalcFrame") or WinExist("Calculator ahk_class ApplicationFrameWindow")
		if WinActive()
			WinMinimize
		else
			WinActivate
	else
		Run calc.exe
	return
}
;}
This is for the calculator built into Windows which it does not appear you are using. It is automatically on top when run.

You can try using after the Run the WinSet command. It has an option for WinSet, Top,, WinTitle.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
w64bit
Posts: 16
Joined: 08 Aug 2018, 08:30

Re: Small code

09 Aug 2018, 06:37

Thank you, I'll give it a try.
Last edited by w64bit on 12 Aug 2018, 08:42, edited 1 time in total.
w64bit
Posts: 16
Joined: 08 Aug 2018, 08:30

Re: Small code

12 Aug 2018, 08:42

I am ending using v1 EXE conversion of:

Code: Select all

Insert::
#SingleInstance force
if WinExist("Calculator")
    WinActivate
else
    Run "C:\Program Files\Calc.exe"
    WinSet, Top
return
but when Calc is not running, I have to press Insert twice in order to run the EXE converted code twice, to have Calc on top.
If I run it once, half of time the Calc is not on top.
The problem is WinSet, Top.
Is there any elegant fix for this?
Or, if not, how can I run WinSet, Top twice?

I tried also v2 (WinMoveTop instead of WinSet, Top) with the same result.
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: Small code to run Calc

12 Aug 2018, 10:06

example

Code: Select all

#warn
#NoEnv
setworkingdir,%a_scriptdir%
pr=calc.exe
sc=ahk_exe %pr%
return
insert::
IfWinNotExist,%sc%
 Run, %pr%
IfWinNotActive ,%sc%,,WinActivate,%sc%
    WinWaitActive,%sc%
return
esc::exitapp
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Small code

13 Aug 2018, 12:42

w64bit wrote:I am ending using v1 EXE conversion of:

Code: Select all

Insert::
#SingleInstance force
if WinExist("Calculator")
    WinActivate
else
    Run "C:\Program Files\Calc.exe"
    WinSet, Top
return
but when Calc is not running, I have to press Insert twice in order to run the EXE converted code twice, to have Calc on top.
If I run it once, half of time the Calc is not on top.
The problem is WinSet, Top.
Is there any elegant fix for this?
Or, if not, how can I run WinSet, Top twice?

I tried also v2 (WinMoveTop instead of WinSet, Top) with the same result.
You probably have a timing issue with attempting to use WinSet right after the Run before the window exist.

You probably need to use WinWait between the Run and WinSet. You need to use the appropriate window title with WinWait to have the script pause and wait for the specificed window to exist. THEN WinSet it to the top.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, peter_ahk, Spawnova and 350 guests