Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UnityでKeyCodeから入力元デバイスを判定する
//Unity - Scripting API: KeyCode http://docs.unity3d.com/ScriptReference/KeyCode.html
//Axis系はkeycodeから取得できない
//ちなみにintからKeyCodeにキャストは可能
void detectInputDevice( KeyCode kc) {
int keycode = (int)kc;
if ( keycode == 0 ) {
//None
}
else if ( keycode >= 8 && keycode <= 319 ) {
//Keyboard (8=Backspace, 319=Menu)
//厳密には歯抜けになっているはず
}
else if ( keycode >= 323 && keycode <= 329 ) {
//Mouse Button 0-6
}
else if ( keycode >= 330 && keycode <= 429 ) {
//Joystick Button
//ex:joystick 330-349, joystick1 350-369, joystick2 370-389, joystick3 390-409, joystick4 410-429
}
else {
//Unknown
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment