Skip to content

Instantly share code, notes, and snippets.

@nanmo
Created July 4, 2014 04:40
Show Gist options
  • Save nanmo/9ca9fbcc366ffbcd2aaa to your computer and use it in GitHub Desktop.
Save nanmo/9ca9fbcc366ffbcd2aaa to your computer and use it in GitHub Desktop.
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