I write games for people with disabilities. Because they are not always able to use a keyboard and mouse, I use external switches plugged into a modified mouse that converts their switch hits to mouse clicks. These clicks are converted to keystrokes which interact with Unity.
I have to take apart a mouse each time I want to make one of these USB interfaces. It is time consuming and, as I am not trained in electronics, not very durable. I recently found a product online called the “X-keys SE USB Switch Interface”. This interface has 12 inputs and is very solid so it is perfect for what I do.
The problem is that Unity accepts the input from this device when I am running the game in the construction mode but when I build the game it no longer accepts the input from the device.
Is there a way around this? We are starting a non-profit society to share these activities with others and we need a reliable input method.
Would this be considered a bug or a limitation? Because it works in the construction mode but not when the game is actually built I’m not sure what I should try.
I use
if (Input.GetKeyDown (“a”))
Is there another way to check for input that would allow a non keyboard/mouse input?
I was trying to write a script that would poll and check the input key, but I dont reall yknoe how to pull it together. Can someone out there with level 2 brains touch this up? It might help with sorting out the input: Current version not working.
function Update () {
if (Input.GetKeyDown (anyKey))
print(anyKey.name);
}
I know its looking for a string and all, I just dont know how to set it up right. It might help this project, so if anyone wants to catch the ball…
AC
I tried GetKey, GetKeyDown, GetButton, GetButtonDown and anyKey and they all have the same result. The input works fine when I’m in Unity but as soon as I build the game, the input no longer works.
I tried different builds to see if one of them might recognize the USB interface but none of them work either (Intel, Universal, PPC, widget or web).
Does anyone have an idea for a way around this? It’s as if something gets lost when Unity compiles the game and I lose the input functionality. It seems that Unity doesn’t ‘see’ the USB interface after the game is built.
If it turns out that there is no way to get this working, does anyone have any experience with alternate forms of input in Unity besides mouse, keyboard and joystick? I’m looking into the Wiimote option that bliprob is exploring with a plugin but I’d appreciate some other information.
What driver are you using to map the 12 inputs to mouse buttons? Does the device come with its own driver?
Basically, if your multi-button input device gets those inputs mapped to mouse buttons, Unity should see them as such. Otherwise, you’ll need a driver to perform the mapping, or a Unity plugin to poll the USB device for its current state.
“USB Overdrive” is a generic USB driver that can generally handle any of the multi-button mice from the PC world. You can map the various buttons to button and keystroke combinations. It might help in this case.
Also, Tiger/Leopard’s developer tools come with a thing called “USB Prober” that might give you more info on the device’s descriptor record, which might help.
The USB interface comes with its own drivers. When I originally used an adapted mouse, I had no problems with the input inconsistencies in Unity. I tried ‘USB Overdrive’ and it showed that it recognized the interface but it didn’t provide me with the proper buttons to remap.
I’ll look into the ‘USB Prober’ but I’m still confused as to why Unity sees the device in the editor but not when the game is actually built. If the hardware/software is supposed to emulate a keyboard stroke, why doesn’t Unity just believe that a key is being hit? I guess it either overrides the drivers or ignores them.
I have tried some third party drivers for the X-keys and they work perfectly in every situation except for built Unity games.
(Thanks to bliprob for the ControllerMate suggestion)
How does Unity deal with input devices? Is it possible that despite the emulation effect of the drivers that Unity is not looking for input from any non joystick/mouse/keyboard devices?
Still hoping someone has a way around this or a way for Unity to use an input device that can be modified to take single switch inputs by at least 8 sources.
Did you ever have any luck with this? I have run into a bunch of situations where I want to see what inputs are named as I try them and this would be great.
No luck unfortunately. As far as I could gather, Unity will only recognize standard input devices. If I had the professional version, I might be able to get somewhere with plugins, but I don’t, so I haven’t. Sorry I can’t help.
i’m not sure when this was introduced (i’m 1.6) and it’s pretty undocumented. i’d guess it should be Input.anyKey rather than GetKeyDown(anyKey). there’s also Input.inputString which might get you somewhere. can’t promise!
[edit: hmm now that i think, bet inputString probably wouldn’t work. oh well, just a thought. handy anyway.]
well i take that back maybe quick test below returns what key was pressed etc. from a keyboard. not sure it will work with other input tho. so like i say maybe
function Update ()
{
if (Input.anyKey)
{
//Debug.Log shows up in the console
Debug.Log (Input.inputString);
/* or if you want it on a gui text uncomment this
guiText.text = Input.inputString;
*/
}
}
I no longer have the usb interface I was testing, but when I did, Unity would never respond to it. The frustrating thing was that it worked when I was testing the games. Built games and the web player would just sit there as if noting was happening when I used the interface. I though I might be able to get around it with midi or the wiimote plugin but both would require the pro version.
Oh well…
Thanks for the suggestion though. I haven’t given up (yet).
i haven’t messed with other input but a few folks have successfully used rumble pads etc. i think they pretty much work out of the box. don’t know why it would work in editor but not in a build. sounds odd. maybe just an unsupported device issue.
i also should mention that inputString returns the actual character rather than the input. no idea what it returns with a controller.
Thanks for the help. When I tested it I saw that it returned letters and numbers but didn’t seem to name the other keys like “shift” and “enter” etc.
It did seem to respond to them though, which was interesting. My 360 controller had no response at all but that makes sense because it’s not a key. I will check later for InputButton or InputAxis.
Now it doesn’t matter if they key is being held down or not. The game loop sees the key as being pressed regardless of state (held down or hit) and causes performMethod() to trigger.
Don’t know if this helps any.
I am still an amature around here.