Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Joystick support


  • Please log in to reply
21 replies to this topic
Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I've added support for joystick hotkeys. In addition, GetKeyState can now retrieve the state of joystick buttons, axis positions, and other info. See the key list for the joystick control names. [thanks compuboy_r & Rajat]

Key List: http://www.autohotke...ocs/KeyList.htm

GetKeyState: http://www.autohotke...GetKeyState.htm

A test script that can help you analyze your joystick(s): http://www.autohotke...oystickTest.htm

And here is the special installer that contains this interim version of the program: http://home.tampabay... ... -input.exe

If anyone has a joystick with lots of buttons and axes, please test it out (mine is just a basic one). In addition, if you happen to have more than one joystick in your system, or can set it up that way, it would be good for someone to test that joysticks beyond the first can be accessed as described in the key list above. Finally, if anyone has Win9x with a joystick, it'd be great if you could try it on there too.

Thanks.

compuboy_r
  • Members
  • 68 posts
  • Last active: Oct 29 2005 03:17 PM
  • Joined: 04 May 2004
CONGRATULATIONS

Man, you are too cool.

Yesterday, I talked u regarding joystick and today its in my hand. GREAT !

well, I tested your support for joystick and found that all is working fine except the U axis. It always shows 00 in place of 50 or anything else.

According to the documentation POV should show 35900 but my joystick shows this:

normal: 65535
up:0
down:17984
left:26976
right:8992

the values u've documented are shown by my joystick driver exactly. but not by AHK's script.

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
WOW!!

Going great guns Chris!!!

another feather in AHK's crown! the 1.0.10 will be a BIG one!!

i've checked and my results matched compuboy_r's.

i think we should wait till some more users put up their reviews.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for the fast tryouts.

all is working fine except the U axis. It always shows 00 in place of 50 or anything else.

I don't see anything wrong in the code. Is it possible your joystick doesn't have that particular axis?

According to the documentation POV should show 35900

According to the AHK docs you mean? If so, that's just the maximum value. I think most joysticks will never show anything beyond 27000 (270 degrees) because the POV control is not "fine", having only 5 possible settings.

but my joystick shows this:
normal: 65535

I think I fixed that so that it will show -1 instead. If you get time, maybe you can re-download and test since I have no way of testing it prior to the 1.0.10 release on Tuesday.

up:0
down:17984
left:26976
right:8992

Well those are close to the expected values (if you assume that up is looking forward and down is looking backward). I'm having AHK return the raw POV value in this case, since I thought that trying to translate it into a percentage might mess it up for some joysticks.

the values u've documented are shown by my joystick driver exactly. but not by AHK's script.

Do you mean that your driver has some utility that reveals, for example, that POV-right is exactly 9000 and not 8992?

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
I'd almost done the cmd auto-completion script that used tooltips (intellisense-like) ...the only thing left was support for 2 cmds on same line. the script was lying in the extras\textpad folder.

i tried the new installation and it deleted the script!!! $%$#%$*&

:evil: :evil: :evil:

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


compuboy_r
  • Members
  • 68 posts
  • Last active: Oct 29 2005 03:17 PM
  • Joined: 04 May 2004

I don't see anything wrong in the code. Is it possible your joystick doesn't have that particular axis?


I confirmed that my joystick has this axis. I have a joystick ( Playstation DualShock (Attached to PC)) that has 6 Axis and all are working in the driver.


According to the AHK docs you mean? If so, that's just the maximum value. I think most joysticks will never show anything beyond 27000 (270 degrees) because the POV control is not "fine", having only 5 possible settings.


Yes, I think the POV control is not "fine" b'coz it now shows me 4294967295 instead of 65535

Do you mean that your driver has some utility that reveals, for example, that POV-right is exactly 9000 and not 8992?


Yes, my driver has a utility which helps me to see the current state of joystick.



Moreover,

How can joystick buttons be used for the hotkeys. I tried

joy1::

and it worked.

Is there any otherway of adding the joystick hotkey and what about axis to hotkey? What about multiple joystick hotkeys. is it like

1joy1::
2joy1::


And atlast, where is the new source code, can i get it before release.


compuboy_r

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

I confirmed that my joystick has this axis.

Ok. I can't explain the problem but maybe someone else with a 6-axis joystick can see if they have the same issue. I've included the source code below so that you can check it for anything wrong.

Yes, I think the POV control is not "fine" b'coz it now shows me 4294967295 instead of 65535

Ok I changed the installer again, hopefully it really will show -1 now. Thanks for your patience. It's at http://home.tampabay... ... -input.exe


Yes, my driver has a utility which helps me to see the current state of joystick.


Well it must be doing some rounding off. Unless you think I should change it, I will leave AHK's POV reporting the way it is.


I tried
joy1::
and it worked.
Is there any otherway of adding the joystick hotkey

For now, that's the only way to do it.

and what about axis to hotkey?

Not supported yet, but planned for a later version. In the meantime, you can make your joystick buttons "context sensitive" based on the axis position as in this example:
joy2::
GetKeyState, joyx, JoyX
if joyx > 75
     MsgBox Action #1 (joystick is pushed to the right).
else if joyx < 25
     MsgBox Action #2 (joystick is pushed to the left).
return

What about multiple joystick hotkeys. is it like

Can you clarify? The first number (to the left of the word joy) is the joystick number. Normally you omit this since it uses the first joystick by default. Your example (as written) would assign the first button on both of the first two joysticks to do the same action, e.g.:
1joy1::
2joy1::
MsgBox You pressed the first button on either joystick #1 or joystick #2.
return

And atlast, where is the new source code, can i get it before release.

It's at http://www.autohotke... ... source.zip

Thank for your testing.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

tried the new installation and it deleted the script!!! $%$#%$*&


Sorry about that. It does that to clean up obsolete files in there. Do you have an undelete utility?

compuboy_r
  • Members
  • 68 posts
  • Last active: Oct 29 2005 03:17 PM
  • Joined: 04 May 2004
Working

Checked AGAIN and found that its working there. It is showing the UAxis and POV correctly.

GOOD JOB CHRIS !!!!!


compuboy_r

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Well, I didn"t change anything about the U axis, but I'm glad it's working. Thanks for the repeated re-testing.

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
This i guess isn't supported till now:
Send, {Joy1}

well i'm sure the above will be reqd by gamers, as a person who'll use AHK to script a complex maneuver in a game (that supports Joystick) and assigns it to a free button wudn't like to assign keybd keys to controls first and then send them......and a way to set axis positions too shuld be considered.

or maybe that's planned for a later version?

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Google doesn't know much about simulating joystick input. There doesn't appear to be an easy way to do it, though perhaps there is some way with the Direct Input API.

compuboy_r
  • Members
  • 68 posts
  • Last active: Oct 29 2005 03:17 PM
  • Joined: 04 May 2004
Rajat has made a good point. GOOD JOB MAN !!!


A few more commands related to joystick are also left, such as

GetJoyButtons , NumberOfButtons, JOY_ID
GetJoyAxis, NumberOfAxis, JOY_ID

This would return the number of Buttons and Axis present in the joystick.


GetKeyState used for the buttons or axis that is not present gives U (up) but should give 0 to inform that the axis or button is not present

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

GetJoyButtons , NumberOfButtons, JOY_ID
GetJoyAxis, NumberOfAxis, JOY_ID

I've added the following to the interim version. I'd appreciate it if you and anyone else can test them out if you get time:
(for use with GetKeyState):
JoyName: The name of the joystick or its driver.
JoyButtons: The number of buttons supported by the joystick (not always accurate).
JoyAxes: The number of axes supported by the joystick.
JoyInfo: Provides a string consisting of one or more of the following letters: Z (has Z axis), R (has R axis), U (has U axis), V (has V axis), P (has POV control), D (the POV control has a limited number of discrete/distinct settings), C (the POV control is continous/fine). Example string: ZRUVPD

GetKeyState used for the buttons or axis that is not present gives U (up) but should give 0 to inform that the axis or button is not present

That's actually normal because it avoids having to query the joystick capabilities every time you want to find out if a button is down or up. Now that you can find out the number of buttons, it's probably not needed to change the current reporting as "default up"?

I've also improved the test script. If you could test that, it'd be great:
http://www.autohotke...oystickTest.htm

Interim version: http://home.tampabay... ... -input.exe

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
this one uses ToolTip and as it auto expands to accomodate all the text and uses lesser space, i feel it works nicer.

coordmode, tooltip, screen
#SingleInstance
;SplashTextOn, 400, , JoyStartingTitle
;WinWait, JoyStartingTitle  ; Set the last found window.
SetFormat, float, 03  ; Omit decimal point from axis position percentages.
;SetFormat, float, 02  ; Omit decimal point from axis position percentages.
JoyStickNumber = 1  ; Increase this to test a joystick other than the first.
GetKeyState, axis_count, %JoyStickNumber%JoyAxes
if axis_count < 1
{
	MsgBox Joystick #%JoyStickNumber% does not appear to be attached to the system.
	ExitApp
}
GetKeyState, joy_buttons, %JoyStickNumber%JoyButtons
GetKeyState, joy_name, %JoyStickNumber%JoyName
GetKeyState, joy_info, %JoyStickNumber%JoyInfo
GetKeyState, joy_axes, %JoyStickNumber%JoyAxes
Loop
{
	buttons_down =
	Loop, %joy_buttons%
	{
		GetKeyState, joy%a_index%, %JoyStickNumber%joy%a_index%
		if joy%a_index% = D
			buttons_down = %buttons_down%%a_space%%a_index%
	}
	GetKeyState, joyx, %JoyStickNumber%JoyX
	axis_info = X%joyy%
	GetKeyState, joyy, %JoyStickNumber%JoyY
	axis_info = %axis_info%%a_space%%a_space%Y%joyy%
	IfInString, joy_info, Z
	{
		GetKeyState, joyz, %JoyStickNumber%JoyZ
		axis_info = %axis_info%%a_space%%a_space%Z%joyz%
	}
	IfInString, joy_info, R
	{
		GetKeyState, joyr, %JoyStickNumber%JoyR
		axis_info = %axis_info%%a_space%%a_space%R%joyr%
	}
	IfInString, joy_info, U
	{
		GetKeyState, joyu, %JoyStickNumber%JoyU
		axis_info = %axis_info%%a_space%%a_space%U%joyu%
	}
	IfInString, joy_info, V
	{
		GetKeyState, joyv, %JoyStickNumber%JoyV
		axis_info = %axis_info%%a_space%%a_space%V%joyv%
	}
	IfInString, joy_info, P
	{
		GetKeyState, joyp, %JoyStickNumber%JoyPOV
		axis_info = %axis_info%%a_space%%a_space%POV%joyp%
	}
	; It's a little less rough on the system to use WinSetTitle vs. SplashTextOn:
	ToolTip, %joy_name%: %axis_info%  Buttons Down: %buttons_down%, 0, 0
	Sleep, 100
}
return

#x::Exitapp

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat