Get the name of a screen Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
FredVN
Posts: 6
Joined: 07 Apr 2019, 10:44

Get the name of a screen

18 Apr 2019, 02:44

I just bought a separate pc for receiving weather satellites and weather information. I use AHK for automating some processes.

One program (Wxtoimg-Pro) has a problem: the Auto Record button switches off after receiving a satellite. The program is not maintained anymore so I cannot ask the author.

So I wrote a AHK-script that presses the Auto Record button every 15 minutes, triggered by the Windows task Planner. Works OK.

Problem is that when I am working on one of the other programs, the Wxtoimg-screen pops up and remains there.

So I thought of the following solution. In the beginning of the script I look what screen is active, continue the script and at the end I activate again the screen that was active in the beginning.

I looked to a lot of commands and examples on the forum, tried a lot but did not find a solution. Anybody who can show me the way?

Thanks in advance.
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Get the name of a screen

18 Apr 2019, 03:01

FredVN wrote:
18 Apr 2019, 02:44
I just bought a separate pc for receiving weather satellites and weather information. I use AHK for automating some processes.

One program (Wxtoimg-Pro) has a problem: the Auto Record button switches off after receiving a satellite. The program is not maintained anymore so I cannot ask the author.

So I wrote a AHK-script that presses the Auto Record button every 15 minutes, triggered by the Windows task Planner. Works OK.

Problem is that when I am working on one of the other programs, the Wxtoimg-screen pops up and remains there.

So I thought of the following solution. In the beginning of the script I look what screen is active, continue the script and at the end I activate again the screen that was active in the beginning.

I looked to a lot of commands and examples on the forum, tried a lot but did not find a solution. Anybody who can show me the way?

Thanks in advance.
Post your code and I'm sure we could help
-TL
FredVN
Posts: 6
Joined: 07 Apr 2019, 10:44

Re: Get the name of a screen

18 Apr 2019, 08:29

The problems are in the “Get” and “Make” parts. The others are working fine.

I tried a lot of command. These are the last attempts. There were a lot of –not working- before these.

Code: Select all

;****************************************************
;Dit script:
;  Get the active screen
;  Press the Record Auto button
;  Restores the previous active screen   
;
;Auteur: Fred van den Bosch
;****************************************************

;****************************************************
; Get the name of the acive screen and put it into ActiefScherm
;****************************************************
WinGet, ActiefScherm, ProcessName, hwnd

;****************************************************
; Press Auto Record button
;****************************************************
WinActivate, WXtoImg [Registered to Fred van den Bosch]
ControlClick, X348 Y11	
Sleep, 1000
WinActivate, WXtoImg:
Send, {Alt}+{F}
Send, {e}
Sleep, 500
WinActivate, WXtoImg: Record
WinWaitActive, WXtoImg: Record
Sleep, 500
MouseMove, 72, 562
Sleep, 500
MouseClick,, 72, 562
Sleep, 500

;****************************************************
; Make the previous screen active
;****************************************************
WinActivate, ActiefScherm

;****************************************************
; End
;****************************************************
Process, Close, Wxtoimg Auto
Process, Close, AutoHotKey.exe
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get the name of a screen

18 Apr 2019, 08:44

I would try these 2 commands:
WinMenuSelectItem - Syntax & Usage | AutoHotkey
https://autohotkey.com/docs/commands/WinMenuSelectItem.htm
ControlClick - Syntax & Usage | AutoHotkey
https://autohotkey.com/docs/commands/ControlClick.htm

Or instead of WinMenuSelectItem (more advanced):
Get Info from Context Menu - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/19754-get-info-from-context-menu/

I would consider WinClose instead of Process Close, and ExitApp to end the script:

Code: Select all

WinClose, Wxtoimg Auto
ExitApp ;close this AutoHotkey script
To get the active window, and make it active 5 seconds later:

Code: Select all

WinGet, hWnd, ID, A
Sleep, 5000
WinActivate, % "ahk_id " hWnd
Last edited by jeeswg on 18 Apr 2019, 10:51, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
FredVN
Posts: 6
Joined: 07 Apr 2019, 10:44

Re: Get the name of a screen

18 Apr 2019, 10:48

Thanks for your answer.
The WinClose and ExitApp are working now.

To activate the previous window does not work yet.
I have added a messagebox after the WinGet in the beginning and just before the WinActivate at the end and both give the same value.
But the wxtoimg window remains in the front.
So my guess is that the problem is in the WinActivate.

I live in Vietnam (I am Dutch), so time to go to bed.
Tomorrow I will continue trying to get it working.
FredVN
Posts: 6
Joined: 07 Apr 2019, 10:44

Re: Get the name of a screen

18 Apr 2019, 23:36

I found the cause of the problems. For a solution there is a big lack of AHK-knowledge here.

Code: Select all

WinActivate, Digital Atmosphere
Sleep, 2000
WinGet, hWnd, ID, A

First I opened a screen of Digital Atmosphere and also added a WinActivate for that screen to my Wxtoimg-script
Now when running the script in the beginning and at the end the DA-screen pops up.
Which means that without the WinActivate the DA-screen is not the active screen when opening the wxtoimg-script but that's somehow overwritten by starting the wxtoimg-script.

So the question is now, is it possible to know what the active screen was just before the wxtoimg-script is started?
FredVN
Posts: 6
Joined: 07 Apr 2019, 10:44

Re: Get the name of a screen

21 Apr 2019, 02:26

"So the question is now, is it possible to know what the active screen was just before the wxtoimg-script is started?"

Anybody who has suggestions how to do this?
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Get the name of a screen

21 Apr 2019, 05:42

FredVN wrote:
21 Apr 2019, 02:26
"So the question is now, is it possible to know what the active screen was just before the wxtoimg-script is started?"

Anybody who has suggestions how to do this?
Put this at the beginning of your script. This gives you some information on the active process before the script start.

Code: Select all

WinGet, ID, ID, A
WinGet, prc, ProcessName, ahk_id %id%
WinGetClass, Cls, ahk_id %id%
WinGetTitle, tit, ahk_id %id%

MsgBox,% format("Process`t{}`nClass`t{}`nTitle`t{}", prc,cls,tit)
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
FredVN
Posts: 6
Joined: 07 Apr 2019, 10:44

Re: Get the name of a screen  Topic is solved

21 Apr 2019, 10:16

YES! It works.

In fact the first suggestion from jeeswg also worked. But with these extra lines I found out that running the script does not work.
But compiling the script and put the .exe-file in the taskplanner did the trick.

Thanks everyone for the tips. I am very happy with the result!.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750, nacken012 and 227 guests