Notification that part of script is running? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Notification that part of script is running?

Post by sws224 » 28 Nov 2022, 19:14

Hello

I have a fairly long script that runs different work shortcuts. Part of the script I only want to use when in a specific program, so I am using a toggle that way I can turn those shortcuts on and off when I am using that program. SO far it is working great. However, I keep forgetting to toggle the specific shortcuts on and off sometimes. I tried using a tooltip but it only stays when I hit the toggle key and also shows up whether I am toggling the specific section on and off (not just when it's on or off).

Any suggestions?

Here is the part of the script I am referring to:

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 28 Nov 2022, 19:15

Sorry, here is the code:

Code: Select all

ScrollLock::
mode := !mode ; Set mode either to 1 or 0 - toggle
ToolTip, "Relativity Toggle"
setTimer, tooltipoff, 2000 ; run tooltipoff after 2 second
return

tooltipoff:
ToolTip ; remove tooltip
return

;Use , (or <) to copy last entry
#if mode = 1
,::send ^+Z
Return

;Use / (or ?) to Open Native Mode
#if mode = 1
/::SendInput !v
Return

;Use ' to Open Image Mode
#if mode = 1
'::SendInput !i
Return

;Use . (or >) to save and move to next document
#if mode = 1
.::SendInput !{enter}
Return

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

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

Re: Notification that part of script is running?

Post by mikeyww » 28 Nov 2022, 19:16

Welcome to this AutoHotkey forum!

AutoHotkey can do the "toggling" for you. https://www.autohotkey.com/docs/commands/_IfWinActive.htm

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Notification that part of script is running?

Post by boiler » 28 Nov 2022, 19:16

If you use the #IfWinActive directive to make your shortcuts/hotkeys automatically active only when a certain application's window is active, you don't have to bother with toggling anything on or off, and you don't have to remember or display the state it's in.

Edit: What mikeyww said. ;)

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 29 Nov 2022, 09:32

Right, but the problem is that this is a specific tab (and specific website) in Chrome. So I don't think AHK can tell when it's that tab open... Also I would need to toggle it if I need to type normally in that tab, which happens often.

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 29 Nov 2022, 09:34

boiler wrote:
28 Nov 2022, 19:16
If you use the #IfWinActive directive to make your shortcuts/hotkeys automatically active only when a certain application's window is active, you don't have to bother with toggling anything on or off, and you don't have to remember or display the state it's in.

Edit: What mikeyww said. ;)
Thanks, but this is for a specific website that I have to use often. I need other parts of chrome and when I switch back and forth between other tabs to have a normal keyboard. I don't mind toggling, I just often forget to press the toggle hotkey (ScrlLck) and it causes issues in other programs/tabs. That's why I just need the code above to include some sort of trigger that when I activate the toggle with ScrlLck it also makes either a message box or tool tip, or something else that will let me know the mode is on, and the shortcuts are activated. Thanks!!!

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Notification that part of script is running?

Post by boiler » 29 Nov 2022, 10:07

sws224 wrote: Right, but the problem is that this is a specific tab (and specific website) in Chrome. So I don't think AHK can tell when it's that tab open...
Yes it can. Use the Window Spy tool that comes with AHK to see what the title is when a particular website is the active tab in Chrome.


sws224 wrote: Also I would need to toggle it if I need to type normally in that tab, which happens often.
You could have a combination of a toggle and a certain website being active using #If and multiple conditions including WinActive().

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 29 Nov 2022, 10:29

boiler wrote:
29 Nov 2022, 10:07
sws224 wrote: Right, but the problem is that this is a specific tab (and specific website) in Chrome. So I don't think AHK can tell when it's that tab open...
Yes it can. Use the Window Spy tool that comes with AHK to see what the title is when a particular website is the active tab in Chrome.


sws224 wrote: Also I would need to toggle it if I need to type normally in that tab, which happens often.
You could have a combination of a toggle and a certain website being active using #If and multiple conditions including WinActive().
But the tab's URL changes all the time. Not sure how a windows spy would determine what that tab is for the given URL... The script already works perfectly for my needs, it's just not working as far as letting me know when the code is active or not. Is there really no other way to create an indicator?

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 29 Nov 2022, 10:32

I already have the toolip show up whenever the hotkey is pressed maybe there's a way to just keep the tooltip persistenly on whille the toggle is pressed and turn off the tooltip when I toggle off this part of the code?

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Notification that part of script is running?

Post by boiler » 29 Nov 2022, 11:13

If your only issue is that the ToolTip you already have stays on temporarily, then just remove the part where you set a SetTimer to turn it off.

In general, there are countless ways to display an indicator of the toggle status. What do you want it to do and look like? Where do you want it to be located on the screen? Will a ToolTip that doesn't disappear meet your needs?

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 29 Nov 2022, 12:09

boiler wrote:
29 Nov 2022, 11:13
If your only issue is that the ToolTip you already have stays on temporarily, then just remove the part where you set a SetTimer to turn it off.

In general, there are countless ways to display an indicator of the toggle status. What do you want it to do and look like? Where do you want it to be located on the screen? Will a ToolTip that doesn't disappear meet your needs?
If I can have the tooltip stay on as long as the toggle is activated (I think the setting is mode=1 to activate the specific part of the script) that would be PERFECT!

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Notification that part of script is running?

Post by boiler » 29 Nov 2022, 13:06

Try this:

Code: Select all

CoordMode, ToolTip, Screen
ScrollLock::ToolTip, % (mode := !mode) ? "Hotkeys active" : "", 0, 0
#If mode
,::send ^+Z ;Use , (or <) to copy last entry
/::SendInput !v ;Use / (or ?) to Open Native Mode
'::SendInput !i ; ;Use ' to Open Image Mode
.::SendInput !{enter} ;Use . (or >) to save and move to next document

The ToolTip will appear in the upper-left corner of the screen. Some extraneous things removed as well: = 1 in the condition expression, Return after a single-line hotkey, redundant #If directives.

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 29 Nov 2022, 13:20

boiler wrote:
29 Nov 2022, 13:06
Try this:

Code: Select all

CoordMode, ToolTip, Screen
ScrollLock::ToolTip, % (mode := !mode) ? "Hotkeys active" : "", 0, 0
#If mode
,::send ^+Z ;Use , (or <) to copy last entry
/::SendInput !v ;Use / (or ?) to Open Native Mode
'::SendInput !i ; ;Use ' to Open Image Mode
.::SendInput !{enter} ;Use . (or >) to save and move to next document

The ToolTip will appear in the upper-left corner of the screen. Some extraneous things removed as well: = 1 in the condition expression, Return after a single-line hotkey, redundant #If directives.
Thank you! Where would I put this in relation to the code I posted above? And will this affect anything else in my whole script?

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Notification that part of script is running?

Post by boiler » 29 Nov 2022, 13:23

sws224 wrote: Where would I put this in relation to the code I posted above?
In place of all of it. Delete what you posted. Paste this in its place.

sws224 wrote: And will this affect anything else in my whole script?
If your script worked with it before, it would affect nothing. This is a direct functional replacement. Just put the first line at the top of your script to make sure it's in the auto-execute section. The rest can go where you had it.

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 29 Nov 2022, 13:26

boiler wrote:
29 Nov 2022, 13:23
sws224 wrote: Where would I put this in relation to the code I posted above?
In place of all of it. Delete what you posted. Paste this in its place.

sws224 wrote: And will this affect anything else in my whole script?
If your script worked with it before, it would affect nothing. This is a direct functional replacement. Just put the first line at the top of your script to make sure it's in the auto-execute section. The rest can go where you had it.
I put it at the bottom of the script where it was originally, it's working BEAUTIFULLY! Thank you very much. I don't know how I can repay you for your time and help!!

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Notification that part of script is running?

Post by boiler » 29 Nov 2022, 13:30

You're welcome. The best thing you can do is study the things we showed you and try to learn the concepts.

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 29 Nov 2022, 14:00

boiler wrote:
29 Nov 2022, 13:30
You're welcome. The best thing you can do is study the things we showed you and try to learn the concepts.
Will DO!

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 05 Dec 2022, 23:15

boiler wrote:
29 Nov 2022, 13:30
You're welcome. The best thing you can do is study the things we showed you and try to learn the concepts.
Sorry one follow up question that I cannot seem to figure out,

In this part of my script:

Code: Select all

CoordMode, ToolTip, Screen
ScrollLock::ToolTip, % (mode := !mode) ? "Mode Active!" : "", 0, 0
#If mode
,::send ^+z ;Use , (or <) to copy last entry
/::SendInput !v ;Use / (or ?) to Open  Mode
'::SendInput !i ; ;Use ' to Open Mode
.::SendInput !{enter} ;Use . (or >) to save and move to next 
;*::SendInput {^+Z} {!{enter}}  ;Use 0 to copy last and then move to next .
I wanted to make just one key press (such as 0) or something else, do the same thing as the , and the . is doing (in that order). So instead of having to press , and then . as I often have to do, I can just hit 0 on my keyboard and have it input both in succession. Is there a way of doing this?

Thank you!


[Mod edit: Added [code][/code] tags. Please use them yourself when posting code :!: ]

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Notification that part of script is running?

Post by boiler » 05 Dec 2022, 23:32

Why not just make a hotkey out of 0 that sends what you want it to?

Code: Select all

0::Send ^+z!{Enter}

Also, please put [code][/code] tags around the code in your posts.

sws224
Posts: 14
Joined: 28 Nov 2022, 19:11

Re: Notification that part of script is running?

Post by sws224 » 06 Dec 2022, 10:51

Thank you but that doesnt work. I need there to be a delay between the two hotkeys (at least one second) otherwise the program doesnt pick up the fact that I'm entering two separate hotkeys.

Post Reply

Return to “Ask for Help (v1)”