Input - Joystick keys not working?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mebo
Posts: 14
Joined: 22 Apr 2021, 16:08

Input - Joystick keys not working?

29 Apr 2021, 23:29

Hey there,

I'm trying to have my script detect either a few keyboard keys or any joystick key to trigger the continuation of said script. The script is rather large, but here's a snippet of the problem:

Code: Select all

if (LineByLineDialog = 1) {
  for index, sentence in StrSplit(Clipboard, "`n`n") {
      GuiControl, 2:Text, Clip, %sentence%
      Input, UserInput, L1 V, {Joy1}{Joy2}{Joy3}{Joy4}{Joy5}{Joy6}{Joy7}{Joy8}{Joy9}{Joy10}{Joy11}{Joy12}{Joy13}{Joy14}{Joy15}{Joy16}{Enter}{Esc}{Up}{Down}{Left}{Right}
  }
}

else {
  GuiControl, 2:Text, Clip, %Clipboard%
}
Right now, the Enter, Escape and arrow keys are detected, but none of the Joystick keys will move the script to forward. I tried to use `KeyWait`, but I need to be able to specify multiple keys, which Input was suggested to use instead. For the record, KeyWait works with Joy4 for example, so my controller inputs are being detected.

Any idea why none of the Joystick options work?
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: Input - Joystick keys not working?

30 Apr 2021, 00:21

I don't see anything documenting why that shouldn't work, but here's another approach:

Demo:

Code: Select all

Keys := "Joy1,Joy2,Joy3,Joy4,Joy5,Joy6,Joy7,Joy8,Joy9,Joy10,Joy11,Joy12,Joy13,Joy14,Joy15,Joy16,Enter,Esc,Up,Down,Left,Right"

Input := GetKeyPress(Keys)
MsgBox, % Input
return

GetKeyPress(keyStr) {
	keys := StrSplit(keyStr, ",")
	loop
		for each, key in keys
			if GetKeyState(key)
				return key
}

In your code:

Code: Select all

Keys := "Joy1,Joy2,Joy3,Joy4,Joy5,Joy6,Joy7,Joy8,Joy9,Joy10,Joy11,Joy12,Joy13,Joy14,Joy15,Joy16,Enter,Esc,Up,Down,Left,Right"

if (LineByLineDialog = 1) {
  for index, sentence in StrSplit(Clipboard, "`n`n") {
      GuiControl, 2:Text, Clip, %sentence%
      Input := GetKeyPress(Keys)
  }
}

else {
  GuiControl, 2:Text, Clip, %Clipboard%
}

return

GetKeyPress(keyStr) {
	keys := StrSplit(keyStr, ",")
	loop
		for each, key in keys
			if GetKeyState(key)
				return key
}
mebo
Posts: 14
Joined: 22 Apr 2021, 16:08

Re: Input - Joystick keys not working?

30 Apr 2021, 11:55

Thanks - that does look clean.

Yep, I thought the same. Not sure why {Joy1} or any of the buttons are picking up with Input though.
mebo
Posts: 14
Joined: 22 Apr 2021, 16:08

Re: Input - Joystick keys not working?

30 Apr 2021, 16:31

I just realized your code is actually different and not just a rewrite. Sorry about that :)

I tried your modification just now and it does accept joystick input, but it appears to be skipping through the loop to the very end.

In this example, my clipboard could look like the following:
"To some people, ore looks like junk. But to us blacksmiths, it's a fascinating treasure trove.

"Even things that look like junk can produce something of value from them. That's what being a craftsman is all about.

"If you want to become a blacksmith, you should go to the Weaponsmith Guild headquarters at Castle Glenn.
With my for loop of splitting the strings on a double new line, this would create an array with having all three of these sentences broken out into one sentence each (instead of all being spit out at once). When you execute a keypress, it will update the GuiControl to send the next sentence and you would keep pressing any of these buttons to move on to the next sentence. The alteration you provided does accept joystick feedback, but it appears to be sending multiple keypresses, which is moving directly from the first sentence to the last. If I slow it down with a MsgBox, I can see the second sentence come through, but without it, it goes from sentence 1 to 3. I'm still playing with what you provided, but if you have an idea to just make this send a single key, that would be very helpful.

Thanks for your help.
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: Input - Joystick keys not working?

30 Apr 2021, 16:51

I didn't test your code, only my demo, but to get it to register only once, you should be able to simply add a KeyWait to have it wait for the release:

Code: Select all

Keys := "Joy1,Joy2,Joy3,Joy4,Joy5,Joy6,Joy7,Joy8,Joy9,Joy10,Joy11,Joy12,Joy13,Joy14,Joy15,Joy16,Enter,Esc,Up,Down,Left,Right"

if (LineByLineDialog = 1) {
  for index, sentence in StrSplit(Clipboard, "`n`n") {
      GuiControl, 2:Text, Clip, %sentence%
      Input := GetKeyPress(Keys)
  }
}

else {
  GuiControl, 2:Text, Clip, %Clipboard%
}

return

GetKeyPress(keyStr) {
	keys := StrSplit(keyStr, ",")
	loop
		for each, key in keys
			if GetKeyState(key) {
				KeyWait, %key%
				return key
			}
}
mebo
Posts: 14
Joined: 22 Apr 2021, 16:08

Re: Input - Joystick keys not working?

30 Apr 2021, 16:55

That did it - amazing! Thanks a bunch for your quick help, boiler. Have a great weekend!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, Spawnova and 128 guests