Rewrite my script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kpoxo6op
Posts: 2
Joined: 17 Jul 2018, 21:25

Rewrite my script

17 Jul 2018, 22:35

Image

hi, I have created script which cycles through keys Q,W,E,R using mouse scroll. This helps to select a card on Android emulator with a mouse wheel.

Code: Select all

startPos := 0
endPos := 3
pos := startPos

WheelDown::
if (pos = 0) {
    send {W}
	pos++
	return
} 

else if (pos = 1) {
    send {E}
	pos++
	return
}

else if (pos = 2) {
    send {R}
	pos++
	return
}

else if (pos = 3) {
    send {Q}
	pos := startPos
	return
}

WheelUp::
if (pos = 0) {
    send {R}
    pos := endPos
	return
}

else if (pos = 1) {
    send {Q}
	pos--
	return
}

else if (pos = 2) {
    send {W}
	pos--
	return
}

else if  (pos = 3) {
    send {E}
	pos--
	return
}

Numpad0::
pos := startPos
send {Q}
How do I rewrite my script so it looks more like this?

Code: Select all

keyArray := [Q,W,E,R]
startIndex := 0
Index := startIndex

WheelDown::
Send keyArray[Index]
Shift Index to the Next Element, Jump to 0 index if the last Key reached
return

WheelUp::
Send keyArray[Index]
Shift Index to the Previous Element, Jump to Last index if the first Key reached
return

Numpad0::
Index := startIndex
send {Q}

Rohwedder
Posts: 7627
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Rewrite my script

18 Jul 2018, 03:41

Hallo,
try this:

Code: Select all

Keys = QWER
Counter := 0, KLen := StrLen(Keys)
WheelDown::
    Send, % SubStr(Keys,Counter+1,1)
	Counter := Mod(Counter+1,KLen)
Return
WheelUp::
    Send, % SubStr(Keys,Counter+1,1)
	Counter := Mod(Counter+KLen-1,KLen)
Return
or that:

Code: Select all

Keys := ["Q","W","E","R"]
Counter := 0, KLen := Keys.Length()
WheelDown::
    Send, % Keys[Counter+1]
	Counter := Mod(Counter+1,KLen)
Return
WheelUp::
    Send, % Keys[Counter+1]
	Counter := Mod(Counter+KLen-1,KLen)
Return
kpoxo6op
Posts: 2
Joined: 17 Jul 2018, 21:25

Re: Rewrite my script

18 Jul 2018, 21:06

this is so cool, thank you

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jameswrightesq, wpulford and 416 guests