hotkeys.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. InputHotkey::InputHotkey(string_view name) : name(name) {
  2. }
  3. auto InputHotkey::poll() -> void {
  4. //don't allow hotkeys to trigger while emulator is unfocused
  5. if(!videoInstance.fullScreen()) {
  6. if(!program.focused()) return;
  7. } else {
  8. if(!videoInstance.focused()) return;
  9. }
  10. //don't allow hotkeys to trigger while mapping them
  11. if(hotkeySettings.visible()) return;
  12. if(device && !hotkeySettings.visible()) {
  13. newValue = device->group(groupID).input(inputID).value();
  14. if(oldValue == 0 && newValue == 1 && onPress) onPress();
  15. if(oldValue == 1 && newValue == 0 && onRelease) onRelease();
  16. oldValue = newValue;
  17. }
  18. }
  19. Hotkeys::Hotkeys() {
  20. toggleStatus.onPress = [&] {
  21. if(program.statusLayout.visible()) {
  22. program.hideStatus();
  23. } else {
  24. program.showStatus();
  25. }
  26. };
  27. hotkeys.append(&toggleStatus);
  28. togglePanels.onPress = [&] {
  29. if(program.panelLayout.visible()) {
  30. program.hidePanels();
  31. } else {
  32. program.showPanels();
  33. }
  34. };
  35. hotkeys.append(&togglePanels);
  36. toggleFullscreen.onPress = [&] {
  37. if(!emulator.system.power) return;
  38. emulator.videoToggleFullscreen();
  39. };
  40. hotkeys.append(&toggleFullscreen);
  41. toggleMouseCapture.onPress = [&] {
  42. if(!emulator.system.power) return;
  43. if(!inputInstance.acquired()) {
  44. inputInstance.acquire();
  45. } else {
  46. inputInstance.release();
  47. }
  48. };
  49. hotkeys.append(&toggleMouseCapture);
  50. fastForward.onPress = [&] {
  51. if(!interface) return;
  52. fastForwardVideoBlocking = videoInstance.blocking();
  53. fastForwardAudioBlocking = audioInstance.blocking();
  54. fastForwardAudioDynamic = audioInstance.dynamic();
  55. videoInstance.setBlocking(false);
  56. audioInstance.setBlocking(false);
  57. audioInstance.setDynamic(false);
  58. };
  59. fastForward.onRelease = [&] {
  60. if(!interface) return;
  61. videoInstance.setBlocking(fastForwardVideoBlocking);
  62. audioInstance.setBlocking(fastForwardAudioBlocking);
  63. audioInstance.setDynamic(fastForwardAudioDynamic);
  64. };
  65. hotkeys.append(&fastForward);
  66. saveState.onPress = [&] {
  67. emulator.saveState(stateSlot);
  68. };
  69. hotkeys.append(&saveState);
  70. loadState.onPress = [&] {
  71. emulator.loadState(stateSlot);
  72. };
  73. hotkeys.append(&loadState);
  74. incrementStateSlot.onPress = [&] {
  75. if(stateSlot < 5) stateSlot++;
  76. else stateSlot = 1;
  77. };
  78. hotkeys.append(&incrementStateSlot);
  79. decrementStateSlot.onPress = [&] {
  80. if(stateSlot > 1) stateSlot--;
  81. else stateSlot = 5;
  82. };
  83. hotkeys.append(&decrementStateSlot);
  84. pauseEmulation.onPress = [&] {
  85. if(!interface) return;
  86. toolsMenu.pauseEmulation.setChecked(!toolsMenu.pauseEmulation.checked());
  87. };
  88. hotkeys.append(&pauseEmulation);
  89. exportMemory.onPress = [&] {
  90. if(!interface) return;
  91. interface->exportMemory();
  92. };
  93. hotkeys.append(&exportMemory);
  94. quitEmulator.onPress = [&] {
  95. emulator.quit();
  96. };
  97. hotkeys.append(&quitEmulator);
  98. }
  99. auto Hotkeys::poll() -> void {
  100. for(auto& hotkey : hotkeys) hotkey->poll();
  101. }
  102. auto Hotkeys::bind() -> void {
  103. for(auto& hotkey : hotkeys) {
  104. hotkey->device.reset();
  105. auto part = hotkey->identifier.split("/");
  106. if(part.size() != 5) continue;
  107. hotkey->pathID = part[0].hex();
  108. hotkey->vendorID = part[1].hex();
  109. hotkey->productID = part[2].hex();
  110. string groupName = part[3];
  111. string inputName = part[4];
  112. for(auto& device : inputManager.devices) {
  113. if(hotkey->pathID != device->pathID()) continue;
  114. if(hotkey->vendorID != device->vendorID()) continue;
  115. if(hotkey->productID != device->productID()) continue;
  116. if(auto groupID = device->find(groupName)) {
  117. if(auto inputID = device->group(groupID()).find(inputName)) {
  118. hotkey->device = device;
  119. hotkey->groupID = groupID();
  120. hotkey->inputID = inputID();
  121. }
  122. }
  123. }
  124. }
  125. }