Arrow key toggle and timing help Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Arrow key toggle and timing help

Post by blad4 » 10 Nov 2022, 04:59

Hi, at the moment I have the buttons Up,Down,Left,Right on the following toggle:

Code: Select all

up::
A+=5
if A>90
A=1
gosub sendroutine
return

down::
A-=5
if A<1
A=90
gosub sendroutine
return

right::
A+=1
if A>90
A=1
gosub sendroutine
return

left::
A-=1
if A<1
A=90
gosub sendroutine
return
the

Code: Select all

sendroutine
itself is at the bottom for reference.

Could you guys help me in enhancing the functionality.

When pressing left/right, instead of just decreasing/increasing A by 1 discretely, could we make it continous, on a timer for 3000ms. Then, any Up/Down still performs it's current functionality (+5), but also stops the left/right timer?

Code: Select all

sendroutine:
B:=(A+90)
C:=(A+180)
D:=(A+270)
WinGet, winList, List, ahk_class Afx:0000000140000000:0:0000000000010005:0000000000000000:0000000000000000
Loop % winList
WinMenuSelectItem, Sierra, , CW, %A%&
WinGet, winList, List, ahk_class Afx:0000000140000000:0:0000000000010005:0000000000000000:0000000000000000
Loop % winList
WinMenuSelectItem, Sierra, , CW, %B%&
WinGet, winList, List, ahk_class Afx:0000000140000000:0:0000000000010005:0000000000000000:0000000000000000
Loop % winList
WinMenuSelectItem, Sierra, , CW, %C%&
WinGet, winList, List, ahk_class Afx:0000000140000000:0:0000000000010005:0000000000000000:0000000000000000
Loop % winList
WinMenuSelectItem, Sierra, , CW, %D%&
return

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

Re: Arrow key toggle and timing help  Topic is solved

Post by mikeyww » 10 Nov 2022, 05:35

Code: Select all

Left::
Right::
Up::
Down::
SetTimer, Go, % A_ThisHotkey ~= "t" ? 3000 : "Off"
Go:
a += {Up: 5, Down: -5, Left: -1, Right: 1}[A_ThisHotkey], a := a > 90 ? 1 : a < 1 ? 90 : a
ToolTip, %a%
Gosub, SendRoutine
Return

blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Arrow key toggle and timing help

Post by blad4 » 12 Nov 2022, 17:34

This works amazing!

and

Code: Select all

A_ThisHotkey ~= "t" ? 3000 : "Off"
means the hotkeys themselves can turn the timer on/off themselves.. but specifically what is the

Code: Select all

~= "t" 
part?

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

Re: Arrow key toggle and timing help

Post by mikeyww » 12 Nov 2022, 21:25

That operator is actually indexed in the documentation: https://www.autohotkey.com/docs/Variables.htm#regex.

blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Arrow key toggle and timing help

Post by blad4 » 15 Nov 2022, 07:23

Sorry I'm really struggling to understand this ..
followed by zero or more occurrences of any character,
like, not sure how it can find an occurence of 't'?

But it doesn't matter anyway^, I'll figure it out later

The last little niggle I'm running into is after 'WinActivating' the program, ~20% of the time it is kind of sticky and

Code: Select all

WinMenuSelectItem
doesn't work. Then when I click the menu button and one of the child windows tabs, it works fine again.

When I do this manually via script, like send

Code: Select all

!c
, select the menu item, then

Code: Select all

{enter}
, then the whole program goes crazy!

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

Re: Arrow key toggle and timing help

Post by mikeyww » 15 Nov 2022, 07:26

Things to try:
1. Add Sleep between your key sends.
2. WinActivate by window class instead of (for example) the process name.

Demonstration:

Code: Select all

Left::
Right::
Up::
Down::
MsgBox,, %  A_ThisHotkey
       , % (A_ThisHotkey ~= "t")         " "
         . RegExMatch(A_ThisHotkey, "t") " "
         . Instr(A_ThisHotkey, "t")      " "
         . (A_ThisHotkey = "Left" || A_ThisHotkey = "Right")
Return

blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Arrow key toggle and timing help

Post by blad4 » 26 Nov 2022, 18:47

mikeyww wrote:
15 Nov 2022, 07:26
Things to try:

2. WinActivate by window class instead of (for example) the process name.
If I have two windows open with the same Window classes, how can I make a WinActivate toggle between the two?

I have this that works for the last activated Window

Code: Select all

WinActivate ahk_class Afx:0000000140000000:0:0000000000010003:0000000000000000:0000000000000000

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

Re: Arrow key toggle and timing help

Post by mikeyww » 26 Nov 2022, 19:20

Code: Select all

wClass = Notepad
GroupAdd, set, ahk_class %wClass%
F3::GroupActivate, set, R

blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Arrow key toggle and timing help

Post by blad4 » 30 Nov 2022, 06:11

mikeyww wrote:
26 Nov 2022, 19:20

Code: Select all

wClass = Notepad
GroupAdd, set, ahk_class %wClass%
F3::GroupActivate, set, R
Thanks. Really sorry I can't find anything about 'wClass' in the documentation, I've been looking for days. Could you point me to where I can read about it?

gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: Arrow key toggle and timing help

Post by gregster » 30 Nov 2022, 06:22

It's just a random variable name - well not totally random: Probably it stands for 'window class' or something similar. But you can name it anything you like.
First something gets assigned to that variable (here: the string Notepad), then a bit later the variable gets evaluated. I am sure you have come across this concept before.

blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Arrow key toggle and timing help

Post by blad4 » 30 Nov 2022, 06:26

Oh so it's simply grouping the same classes found into 'set'. Thank you!

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

Re: Arrow key toggle and timing help

Post by mikeyww » 30 Nov 2022, 06:29

I thought it would increase clarity, but it worsened it!

If you click on the posted commands, you can learn more about them.

GroupAdd:
Each use of this command adds a new rule to a group. In other words, a group consists of a set of criteria rather than a fixed list of windows. Later, when a group is used by a command such as GroupActivate, each window on the desktop is checked against each of these criteria. If a window matches one of the criteria in the group, it is considered a match.

Post Reply

Return to “Ask for Help (v1)”