Alwaysontop Script

Discussion, questions and support.
Jim K
Posts: 8
Joined: Nov 12th, ’18, 02:54

Post by Jim K » Nov 12th, ’18, 03:14

My goal is to write a script that will:
1. Load a program
2. Create a ctrl-key (^SPACE) to force that application to always stay on top.
3. Send the ^SPACE to the program to execute the stay-on-top macro.

I have an AutoHotKey script listed below.

When I execute the script, if fulfills the first two steps above. The third step doesn't work. I'm using notepad.exe as an example.

It loads the program, writes 'abc ddd' to the screen, executes the ctrl-key definition, then stops.

When notepad is loaded, it is not AlwaysOnTop. When I send it the ^SPACE manually, it works. So I know the ^SPACE macro was created.

Please help me understand why the commands after the winset are not being executed. (Step 3.)

I want the program to load and be always on top by just running the script.

Here is the script. Thank you for your help.

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

#SingleInstance force

run, notepad.exe
sleep 100

send, abc
send, {SPACE}
send, ddd
sleep 100

^SPACE:: Winset, Alwaysontop, On, Untitled - Notepad
sleep 100

send, eee
sleep 100

send, ^{SPACE}
sleep 100

return
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Nov 12th, ’18, 18:48

The first hotkey label has the same effect as return therefore the lines after it never get executed - move the hotkey line to the end of the script (after return).

But you don't need a hotkey...

Code: Select all

run, notepad
sleep 200
Winset, Alwaysontop, On, Untitled - Notepad
send, abc ddd eee
Jim K
Posts: 8
Joined: Nov 12th, ’18, 02:54

Post by Jim K » Nov 12th, ’18, 20:44

Hi Tom,

Thank you, thank you, thank you!

It works perfectly!

That's what happens when I don't know a language and try to do it from the help files... :(

Jim
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Nov 12th, ’18, 23:01

You are welcome. With a little practice you can learn the basics very quickly, then the sky is the limit. :)
Jim K
Posts: 8
Joined: Nov 12th, ’18, 02:54

Post by Jim K » Nov 13th, ’18, 03:58

Hi Tom,

I'm trying to understand this a little better.

If I delete the word 'Untitled' from the notepad script, it doesn't work. I can't seem to find an explanation of when to use the word 'Untitled'.

If I change the word 'Notepad' to 'notepad' in the Winset command, it doesn't work.

If I run it for the program RobotBASIC.exe, I have to leave off the word 'Untitled' for it to work.

Finally, I'm trying to run a program called TopTest_.BAS, a binary program that uses RobotBASIC, then runs from it. I'd like the TopTest_ program to always stay on top.

If I use:
run TopTest_.BAS
sleep 500
Winset, Alwaysontop, On, TopTest_

It runs the program fine, but it doesn't stay on top.

I've spent hours, and I'm still not quite getting it.

Can you help me understand?

Thank you for your help and support.

Regards,

Jim
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Nov 13th, ’18, 14:01

The third parameter in the WinSet command is Window title.
https://autohotkey.com/docs/commands/WinSet.htm

Window title can be a window name, active window (A), window class, window unique id etc. By default, window name is case sensitive.
https://autohotkey.com/docs/misc/WinTitle.htm
https://autohotkey.com/docs/commands/Se ... chMode.htm

You can find more information about the window using Tools/Window Information tool in FastKeys.

If WinTitle is the letter A, the active window will be used. So the simplest would be to do the following:

Code: Select all

run TopTest_.BAS
sleep 500
Winset, Alwaysontop, On, A
Jim K
Posts: 8
Joined: Nov 12th, ’18, 02:54

Post by Jim K » Nov 13th, ’18, 15:54

Hi Tom,

Thanks for the great references. I'm starting to get it.

I tried your new script. It loads the program but other windows can still cover it.

When it loads, I can see RobotBASIC load first for a fraction of a second, then TopTest_.BAS runs and RobotBASIC disappears, just leaving the application window.

Do I need to get an exact title to identify it?

Thanks,

Jim

Tom.jpg
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Nov 13th, ’18, 17:02

Yes, put the the window title (or beginning of the title) of the window which you would like to stay on top.
Jim K
Posts: 8
Joined: Nov 12th, ’18, 02:54

Post by Jim K » Nov 14th, ’18, 00:20

Sorry I'm so dense. I'm really trying to understand why this isn't working.

Here's the script I'm using;
run TopTest_.BAS
sleep 500
Winset, Alwaysontop, On, C:\Users\Jim\Desktop\TopTest_

I've tried the following combinations:
RobotBASIC Interactive Terminal Screen
RobotBASIC Interactive Terminal Screen [C:\Users\Jim\Desktop\TopTest_.BAS]
[C:\Users\Jim\Desktop\TopTest_.BAS]
C:\Users\Jim\Desktop\TopTest_.BAS
Tom3.jpg
I know I'm doing something stupid. Just can't figure out what. :)
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Nov 14th, ’18, 12:49

This should work (beginning of the window name):

Code: Select all

run TopTest_.BAS
sleep 500
Winset, Alwaysontop, On, RobotBASIC
If not, maybe you need to increase a sleep.
Post Reply