 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
jimmythehoffa
Joined: 20 Jun 2008 Posts: 5
|
Posted: Fri Jun 20, 2008 6:12 am Post subject: What is maximum number of simultaneous joysticks? |
|
|
I wanted to know what the maximum number of joysticks that could be used simultaneously using AutoHotKey. I've read somewhere that it is up to 32, but I was not able to confirm that in the documentation. I am thinking of creating a game show quiz program that takes input from approximately 30 students simultaneously in a classroom setting. Before I start on that project, I wanted to make sure that AutoHotKey in fact supports up to 32 joysticks before I go out and spend big bucks buying 32 joysticks.
Any input on this issue would be greatly appreciated. Please let me know, also, where you found the information so I can refer to it.
Thanks a lot,
Jimmy |
|
| Back to top |
|
 |
John W
Joined: 09 Apr 2007 Posts: 169
|
Posted: Fri Jun 20, 2008 6:28 am Post subject: |
|
|
If the documentation says you can use up to 32 joysticks, then you can, because the joysticks send information to the computer, AHK retrieves and processes it. The question is - Are you having the possibility to plug in every joystick? _________________ John
Inactive - Until AutoHotkey is available for Linux. |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 914 Location: The Interwebs
|
Posted: Fri Jun 20, 2008 6:34 am Post subject: |
|
|
Well, this is what the documentation says about multiple joysticks:
| The Manual wrote: | | Multiple Joysticks: If the computer has more than one and you want to use one beyond the first, include the joystick number in front of the control name. For example, 2joy1 is the second joystick's first button. |
Soo... It doesn't seem to give a limit. |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1129
|
Posted: Fri Jun 20, 2008 7:52 am Post subject: |
|
|
I couldn't find a limit to the number of joysticks given in the documentation, only a limit to the number of buttons on each joystick (32).
Presumable, the USB interface system is what limits the total number of supported devices (I think it's something like 127 ?? maybe...)
Regardless, AHK should adequately handle 30 joysticks (usb gamepads are usually also detected by AHK as joysticks, and they may be cheaper to buy in bulk). Quick google search
Another issue will probably be power consumption. I would suggest looking into powered 7+ port usb hubs, since 5 of those should meet your target number, even if you chain them.
Choreographing all those devices may be a challenge, perhaps having an AHK script mark the joystick number while taking roll would do the trick (the student whose name were called could sound off and mash the joystick/gamepad at the same time:D).
[edit: deeper google search] _________________ My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Fri Jun 20, 2008 10:13 am Post subject: |
|
|
| script.h wrote: | | #define MAX_JOYSTICKS 16 // The maximum allowed by any Windows operating system. |
|
|
| Back to top |
|
 |
John W
Joined: 09 Apr 2007 Posts: 169
|
Posted: Fri Jun 20, 2008 10:47 am Post subject: |
|
|
Hmm. Recompile with "#define MAX_JOYSTICKS 32"?
Then it should work. _________________ John
Inactive - Until AutoHotkey is available for Linux. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Fri Jun 20, 2008 1:16 pm Post subject: |
|
|
| The Windows Multimedia API (used by AutoHotkey) does not support more than 16 joysticks, as suggested by the comment in my previous post. If you really need more than 16 joysticks, you should research DirectInput. |
|
| Back to top |
|
 |
jimmythehoffa
Joined: 20 Jun 2008 Posts: 5
|
Posted: Fri Jun 20, 2008 2:49 pm Post subject: |
|
|
Thanks for all the quick responses. Lexikos, I believe you are correct, because even though AutoHotKey may support up to 32 joysticks, the operating system may not. The following is part of my script:
1Joy1::Send J1 B1{Enter}
1Joy2::Send J1 B2{Enter}
1Joy3::Send J1 B3{Enter}
1Joy4::Send J1 B4{Enter}
1Joy5::Send J1 B5{Enter}
2Joy1::Send J2 B1{Enter}
2Joy2::Send J2 B2{Enter}
2Joy3::Send J2 B3{Enter}
2Joy4::Send J2 B4{Enter}
2Joy5::Send J2 B5{Enter}
...
16Joy1::Send J16 B1{Enter}
16Joy2::Send J16 B2{Enter}
16Joy3::Send J16 B3{Enter}
16Joy4::Send J16 B4{Enter}
16Joy5::Send J16 B5{Enter}
17Joy1::Send J17 B1{Enter}
17Joy2::Send J17 B2{Enter}
17Joy3::Send J17 B3{Enter}
17Joy4::Send J17 B4{Enter}
17Joy5::Send J17 B5{Enter}
...
and so on up to 32Joy5
When I come to execute the script, I get the following error message:
---------------------
Error at line 81
Line Text: 17Joy1::Send J17 B1{Enter}
Error: Invalid hotkey
The program will exit
---------------------
Even if I try to create a script with one single line, such as:
22Joy1::Send a
I get an error message. It seems that it will not accept values higher than 16 for the joystick number. However, when I run the "JoystickTest.ahk" script found in the help file, I see that it allows me to enter values greater than 16 for the variable "JoystickNumber". However, further experimentation shows that this script allows me to enter pretty much any number, even 1000, and the script still works, I guess waiting from an input from Joystick #1000. This is probably because it's just a variable, and not hard coded into the code, such as 1000Joy1, which wouldn't work.
John W, I tried to recompile with "#define MAX_JOYSTICKS 32" but it gave me an error message, maybe because I'm not placing the statement in the right place in my code?
Before fiddling with AutoHotKey, I tried the Joy2Key software, but it also has a limit of 16 joysticks, which is probably because of the Windows Multimedia API, as Lexikos stated.
Lexikos, any advice as to where I could start on my research with DirectInput, because I actually do really need more than 16 joysticks, since my normal classroom sizes are usually larger than 16 students.
Thanks again for all the helpful responses from everyone. |
|
| Back to top |
|
 |
jimmythehoffa
Joined: 20 Jun 2008 Posts: 5
|
Posted: Fri Jun 20, 2008 3:02 pm Post subject: USB Numeric Keypad Alternative? |
|
|
Since the joystick limit in Windows appears to be 16 simulataneous joysticks, does anyone know how I could implement the same idea of using 32 input devices simultaneously, but use USB Numeric Keypads instead of joysticks? They would need to be enumerated so that each keypad is individually identifiable, which I believe is a problem in itself, where the operating system may see the 32 numeric keypads as one single keyboad input device, perhaps, since the numeric keypads may not be automatically enumerated the same way the joysticks are, at least by AutoHotKey.
Would this setup be possible using AutoHotKey, or using any other method?
Thanks,
Jimmy |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Fri Jun 20, 2008 3:45 pm Post subject: |
|
|
| Code: | | MsgBox % DllCall("winmm.dll\joyGetNumDevs", "UInt") | tells you that the Windows joystick driver can handle max 16 devices. If you have USB joysticks, you might succed with custom device drivers. Some joysticks come with such drivers, and then the limit will be the number of USB devices your Windows version can handle.
There are difficulties with the 16 standard joysticks: if they are the same type, you will not know, which device number corresponds to which joystick, so you would need a calibration/identification step, when the user presses a button of each joystick.
If the joysticks are different, but handled with the Windows joystick driver, you will only know that the “Microsoft PC-joystick driver” is used via DINPUT.DLL, unless you dig in to VxD via the last field of the JOYCAPS structure: | Code: | VarSetCapacity(JOYCAPS, 404, 0)
r := DllCall("winmm.dll\joyGetDevCapsA", "UInt",1, "UInt",&JOYCAPS, "UInt",404, "UInt") | Maybe Sean, or another Windows expert can help with this. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Sat Jun 21, 2008 2:21 am Post subject: |
|
|
| jimmythehoffa wrote: | | However, when I run the "JoystickTest.ahk" script found in the help file, I see that it allows me to enter values greater than 16 for the variable "JoystickNumber". | Load time validation catches this: | Code: | GetKeyState, joy%a_index%, 20joy%a_index%
| JoystickTest.ahk uses the following, which cannot be validated at load-time since it is not known what value(s) JoystickNumber will hold: | Code: | GetKeyState, joy%a_index%, %JoystickNumber%joy%a_index%
| Values over 16 definitely will not work in any way, much like the following: | Code: | n = twenty
GetKeyState, joy, %n%Joy1
MsgBox joy: %joy%`nerr: %ErrorLevel% |
| Quote: | | John W, I tried to recompile with "#define MAX_JOYSTICKS 32" but it gave me an error message, maybe because I'm not placing the statement in the right place in my code? | Even if it compiled, you would not get anything useful from the upper 16 "joysticks."
| Quote: | | Lexikos, any advice as to where I could start on my research with DirectInput, |
MSDN: DirectInput (MSDN started giving me error 404 a few minutes ago .) It won't be simple - the C++ interfaces need to be converted to flat functions for AHK. To do this, you'll probably need to refer to the DirectX SDK. For instance, the following interface is defined in dinput.h:
| Code: | DECLARE_INTERFACE_(IDirectInputDevice8A, IUnknown)
{
/*** IUnknown methods ***/
STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
/*** IDirectInputDevice8A methods ***/
STDMETHOD(GetCapabilities)(THIS_ LPDIDEVCAPS) PURE;
STDMETHOD(EnumObjects)(THIS_ LPDIENUMDEVICEOBJECTSCALLBACKA,LPVOID,DWORD) PURE;
STDMETHOD(GetProperty)(THIS_ REFGUID,LPDIPROPHEADER) PURE;
STDMETHOD(SetProperty)(THIS_ REFGUID,LPCDIPROPHEADER) PURE;
STDMETHOD(Acquire)(THIS) PURE;
STDMETHOD(Unacquire)(THIS) PURE;
STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID) PURE;
STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
STDMETHOD(SetDataFormat)(THIS_ LPCDIDATAFORMAT) PURE;
STDMETHOD(SetEventNotification)(THIS_ HANDLE) PURE;
STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD) PURE;
STDMETHOD(GetObjectInfo)(THIS_ LPDIDEVICEOBJECTINSTANCEA,DWORD,DWORD) PURE;
STDMETHOD(GetDeviceInfo)(THIS_ LPDIDEVICEINSTANCEA) PURE;
STDMETHOD(RunControlPanel)(THIS_ HWND,DWORD) PURE;
STDMETHOD(Initialize)(THIS_ HINSTANCE,DWORD,REFGUID) PURE;
STDMETHOD(CreateEffect)(THIS_ REFGUID,LPCDIEFFECT,LPDIRECTINPUTEFFECT *,LPUNKNOWN) PURE;
STDMETHOD(EnumEffects)(THIS_ LPDIENUMEFFECTSCALLBACKA,LPVOID,DWORD) PURE;
STDMETHOD(GetEffectInfo)(THIS_ LPDIEFFECTINFOA,REFGUID) PURE;
STDMETHOD(GetForceFeedbackState)(THIS_ LPDWORD) PURE;
STDMETHOD(SendForceFeedbackCommand)(THIS_ DWORD) PURE;
STDMETHOD(EnumCreatedEffectObjects)(THIS_ LPDIENUMCREATEDEFFECTOBJECTSCALLBACK,LPVOID,DWORD) PURE;
STDMETHOD(Escape)(THIS_ LPDIEFFESCAPE) PURE;
STDMETHOD(Poll)(THIS) PURE;
STDMETHOD(SendDeviceData)(THIS_ DWORD,LPCDIDEVICEOBJECTDATA,LPDWORD,DWORD) PURE;
STDMETHOD(EnumEffectsInFile)(THIS_ LPCSTR,LPDIENUMEFFECTSINFILECALLBACK,LPVOID,DWORD) PURE;
STDMETHOD(WriteEffectToFile)(THIS_ LPCSTR,DWORD,LPDIFILEEFFECT,DWORD) PURE;
STDMETHOD(BuildActionMap)(THIS_ LPDIACTIONFORMATA,LPCSTR,DWORD) PURE;
STDMETHOD(SetActionMap)(THIS_ LPDIACTIONFORMATA,LPCSTR,DWORD) PURE;
STDMETHOD(GetImageInfo)(THIS_ LPDIDEVICEIMAGEINFOHEADERA) PURE;
}; | STDMETHOD, STDMETHOD_, THIS, etc. are macros defined elsewhere in the Windows SDK. The first three methods are identical to COM_QueryInterface, COM_AddRef and COM_Release in COM.ahk. Where 'device' is a pointer to an IDirectInputDevice8A interface, the C++ code | Code: | | device->SetCooperativeLevel(hwnd, dwFlags) | becomes | Code: | | DllCall(NumGet(NumGet(device+0)+13*4), "uint", device, "uint", hwnd, "uint", dwFlags) | The red part retrieves a pointer to the SetCooperativeLevel method from the VTable (method table) of the interface pointed to by 'device'. 13*4 is used because SetCooperativeLevel is preceded by 13 methods, and each method pointer is 4 bytes (32 bits).
| jimmythehoffa wrote: | | ... how I could implement the same idea of using 32 input devices simultaneously, but use USB Numeric Keypads instead of joysticks? | DLLCall: Support for Human Interface devices
It doesn't seem possible to block the keystrokes from the active window. Pressing 1 on the second keyboard, for example, may be detected as 1 on the second keyboard, but will also type 1 in the active window.
If this is for an application that will exclusively use HID, that shouldn't be a problem. I think it is even possible to disable the "legacy" keyboard messages for windows within your application.
It is also possible to detect joystick input using the HID/Raw Input APIs, but I'm not sure if Micah's script handles that. |
|
| Back to top |
|
 |
jimmythehoffa
Joined: 20 Jun 2008 Posts: 5
|
Posted: Sat Jun 21, 2008 5:00 pm Post subject: |
|
|
Thanks again for all the thorough and in-depth help from everyone.
I realize that the joystick numbering and detection will have to be initialized each time at the beginning of a lesson, for example. I plan to accomplish this by having the student's name appear on the projector screen and they will be asked to press a button on their joystick in order for the program to detect which joystick belongs to which student, systematically asking each student to register their joystick. Even though the operating system may not enumerate the joysticks in the same order each time they are unplugged and plugged back in, at least each joystick can be addressed individually using:
1Joy1:: Send J1-B1{Enter}
2Joy1:: Send J2-B2{Enter}
etc.
I was wondering if there was a similar procedure for other HID devices, such as USB numeric keypads, could be used in AutoHotKey. Something to the effect of:
1Numpad1:: Send Numpad1-Key1{Enter}
1Numpad2:: Send Numpad1-Key2{Enter}
2Numpad1:: Send Numpad2-Key1{Enter}
2Numpad2:: Send Numpad2-Key2{Enter}
I know this is not real code, but hopefully this clarifies a bit what I would be trying to do with the USB numeric keypads, in effect using them in the same manner I'm trying to use the joysticks, but trying to get past the 16-joystick limit in Windows.
Lexikon, regarding your comment on my USB numeric keypad/keyboard idea:
| Quote: | | It doesn't seem possible to block the keystrokes from the active window. Pressing 1 on the second keyboard, for example, may be detected as 1 on the second keyboard, but will also type 1 in the active window. |
Is there at least a way to get AutoHotKey to detect each USB numeric keypad as an individual device, similar to the way it enumerates the joysticks, so that I can bind a hotkey combination to each key on the numeric keypads?
I understand what you're saying about pressing 1 on the first keypad will cause a 1 to be displayed on the screen, since it is actually a keyboard device, so that pressing 1 on either keypad will cause a 1 to be displayed on the screen. Is there a way, despite this issue, to cause a hotkey combination to be executed when the 1 key is pressed?
For example, if I pressed 1 on the first keypad, I could get an output of:
1Numpad1-Key1
and if I pressed 1 on the second keypad, I could get get an output of:
1Numpad2-Key1
I could programatically remove the extra characters that appear in front of the text, such as discarding the first character of the hotkey output string, effectively removing the characters that were printed to the screen due to the fact that the device is actually a keyboard.
My game show quiz program will consist of a textbox that will receive the input commands that are automatically generated by AutoHotkey, and it will process the text in the textbox as soon as it receives the ENTER command, which is why I placed {Enter} at the end of each of my hotkey commands. During the processing of the text that was automatically typed into the textbox by the AutoHotKey script, the first character (unwanted keypad input) would be removed, and the remaining text would be processed in order to determine which key on which numpad was pressed.
So, would it be possible to enumerate the USB numeric keypads in such a manner so that they are individually addressable just like the joysticks are, with a preliminary initialization step taken at the beginning of each class to determine which student is using which keypad?
I will look into the "DLLCall: Support for Human Interface devices" forum
topic you have suggested in your last post. It looks promising.
Thanks so much for your time.
Jimmy |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sat Jun 21, 2008 5:55 pm Post subject: |
|
|
One possible low-cost solution for quiz management with max 32 students:
- Connect 16 gameport to USB adapters ($15 each) to the PC (you might need a couple of USB hubs, $10 each). Each adapter can handle 8 joystick switches.
- Mount 4 pushbutton switches in each of 32 boxes. A switch is about $1, a suitable instrument box is $8.
- Take 16 Y joystick extension cables, cut off their two female connectors and solder the cables directly to the switches inside the boxes, leading the cables through rubber grommets. Two students will share a gameport adapter, but will have their own switch boxes.
If you need to work with more than 32 students, there are other possibilities, too. This USB device can handle more than 100 switches, but I am not sure, if you can use more than one such a device at a time.
This 32 button USB interface simulates two gamepads, so you could (I have not tried) connect 8 of them to a PC, and 8 students to each of them. This way 64 students can have their 4 button boxes.
Please tell us, what you try, what works, and what does not, so others could benefit from your experiences. |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1129
|
Posted: Sat Jun 21, 2008 10:17 pm Post subject: |
|
|
Lol @ Laszlo! That would take hours of soldering and hundreds of ¥£$s!
Better yet would be to buy a bunch of cheapo gamepads/joysticks and just get a second computer to hook up the extras. Then have AHK use a messenger program (msn, aim, etc) to forward data "'packets'" between the two computers. A 'working' ultra-low-end computer should be available at your local dumpster or second-hand shop; or jimmythehoffa knows someone who would be willing to part with their old pentium3 system.
With a second computer, the issue is no longer the 16 joystick limit, but timestamping the event messages (easily done with AHK) _________________ My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sat Jun 21, 2008 10:42 pm Post subject: |
|
|
Since each computer can handle only 16 game controllers or joysticks, you would need 3 PC’s to handle 33 joysticks. Each booted up, and connected to the main PC, running some communication SW. It is not a nice solution, either. To say nothing of the awkward arrangement of the buttons on the joysticks, which makes it hard to use in a quiz. If it is a one-time issue, the couple of hours soldering is much less work than writing the SW and setting up the system. If you want to install a similar configuration many times, a pure SW solution with off the shelf devices was preferable.
Clearly, the best was a bunch of USB numeric keypads connected to a single PC, if we could distinguish their input. With Micha’s HID dll I can distinguish one of such keypads from the main keyboard, but not from a second or third... keypad. Let’s just hope that some device driver guru writes some SW for this. The information is there somewhere deep in Windows, telling the origin of a key press. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|