inputMonitor.tscript 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. function InputMonitorDlg::onWake(%this)
  2. {
  3. if ((%this.maxLines $= "") || (%this.maxLines < 10))
  4. %this.maxLines = 500;
  5. if (%this.axisDeadzone $= "")
  6. %this.axisDeadzone = 0.1;
  7. if (!isObject(InputEventVector))
  8. new MessageVector(InputEventVector);
  9. InputEventVector.clear();
  10. EventVectorCtrl.attach(InputEventVector);
  11. %this.updateDevicesLine();
  12. }
  13. function InputMonitorDlg::updateDevicesLine(%this)
  14. {
  15. %sdlDevices = 0;
  16. if (isMethod("SDLInputManager", "numJoysticks"))
  17. %sdlDevices = SDLInputManager::numJoysticks();
  18. %openDevices = 0;
  19. for (%i = 0; %i < %sdlDevices; %i++)
  20. {
  21. %openState = SDLInputManager::getDeviceOpenState(%i);
  22. if (%openState > 0)
  23. %openDevices++;
  24. }
  25. %this.setDevicesLine(%openDevices, %sdlDevices);
  26. }
  27. function InputMonitorDlg::setDevicesLine(%this, %openDevices, %sdlDevices)
  28. {
  29. %text = %openDevices @ " of " @ %sdlDevices @ " Joystick devices opened";
  30. %this-->devicesLine.setText(%text);
  31. }
  32. function InputMonitorCtrl::onInputEvent(%this, %device, %action, %state)
  33. {
  34. %text = %device @ ", " @ %action @ (%state ? " Make" : " Break");
  35. if (InputEventVector.getNumLines() > InputMonitorDlg.maxLines)
  36. InputEventVector.popFrontLine();
  37. InputEventVector.pushBackLine(%text, 0);
  38. // Test for the reserved keystrokes:
  39. if (%device $= "keyboard")
  40. {
  41. // Cancel...
  42. if (%action $= "escape")
  43. {
  44. Canvas.popDialog(InputMonitorDlg);
  45. return;
  46. }
  47. // Settings...
  48. if ((%action $= "f2") && %state)
  49. {
  50. Canvas.popDialog(InputMonitorDlg);
  51. Canvas.pushDialog(JoystickSettingsDlg);
  52. }
  53. }
  54. }
  55. function InputMonitorCtrl::onAxisEvent(%this, %device, %action, %axisValue)
  56. {
  57. if (mAbs(%axisValue) < InputMonitorDlg.axisDeadzone)
  58. {
  59. if (%this.lastZero[%device@%action])
  60. return;
  61. %this.lastZero[%device@%action] = true;
  62. %axisValue = 0;
  63. }
  64. else
  65. %this.lastZero[%device@%action] = false;
  66. %text = %device @ ", " @ %action SPC %axisValue;
  67. if (InputEventVector.getNumLines() > InputMonitorDlg.maxLines)
  68. InputEventVector.popFrontLine();
  69. InputEventVector.pushBackLine(%text, 0);
  70. }