Prevent repeating key down events

This commit is contained in:
SilentSpike 2015-07-24 11:12:26 +01:00
parent 53a0a9343b
commit 9b3b5e9750
2 changed files with 21 additions and 4 deletions

View File

@ -32,6 +32,7 @@ switch (toLower _mode) do {
// Initalize display variables // Initalize display variables
GVAR(ctrlKey) = false; GVAR(ctrlKey) = false;
GVAR(heldKeys) = [];
GVAR(mouse) = [false,false]; GVAR(mouse) = [false,false];
GVAR(mousePos) = [0.5,0.5]; GVAR(mousePos) = [0.5,0.5];
@ -71,6 +72,7 @@ switch (toLower _mode) do {
// Cleanup display variables // Cleanup display variables
GVAR(ctrlKey) = nil; GVAR(ctrlKey) = nil;
GVAR(heldKeys) = nil;
GVAR(mouse) = nil; GVAR(mouse) = nil;
GVAR(mousePos) = nil; GVAR(mousePos) = nil;
@ -111,7 +113,8 @@ switch (toLower _mode) do {
[localize LSTRING(freeCamRight),"D"], [localize LSTRING(freeCamRight),"D"],
[localize LSTRING(freeCamUp),"Q"], [localize LSTRING(freeCamUp),"Q"],
[localize LSTRING(freeCamDown),"Z"], [localize LSTRING(freeCamDown),"Z"],
[localize LSTRING(freeCamVision),"N"], [localize LSTRING(freeCamNextVis),"N"],
[localize LSTRING(freeCamPrevVis),"Ctrl + N"],
[localize LSTRING(freeCamSpeed),"Scrollwheel"], [localize LSTRING(freeCamSpeed),"Scrollwheel"],
[localize LSTRING(freeCamZoom),"Ctrl + Scrollwheel"] [localize LSTRING(freeCamZoom),"Ctrl + Scrollwheel"]
]; ];
@ -164,6 +167,10 @@ switch (toLower _mode) do {
case "onkeydown": { case "onkeydown": {
_args params ["_display","_dik","_shift","_ctrl","_alt"]; _args params ["_display","_dik","_shift","_ctrl","_alt"];
// Handle held keys (prevent repeat calling)
if (_dik in GVAR(heldKeys)) exitwith {};
GVAR(heldKeys) pushBack _dik;
switch (_dik) do { switch (_dik) do {
case 1: { // Esc case 1: { // Esc
[player,false] call FUNC(setSpectator); // Handle esc menu goes here, currently closes for purposes of testing [player,false] call FUNC(setSpectator); // Handle esc menu goes here, currently closes for purposes of testing
@ -205,7 +212,11 @@ switch (toLower _mode) do {
GVAR(camBoom) = -0.5; GVAR(camBoom) = -0.5;
}; };
case 49: { // N case 49: { // N
[nil,nil,1] call FUNC(cycleCamera); if (_ctrl) then {
[nil,nil,-1] call FUNC(cycleCamera);
} else {
[nil,nil,1] call FUNC(cycleCamera);
};
}; };
case 50: { // M case 50: { // M
[_display,nil,nil,nil,true] call FUNC(toggleInterface); [_display,nil,nil,nil,true] call FUNC(toggleInterface);
@ -234,6 +245,9 @@ switch (toLower _mode) do {
case "onkeyup": { case "onkeyup": {
_args params ["_display","_dik","_shift","_ctrl","_alt"]; _args params ["_display","_dik","_shift","_ctrl","_alt"];
// No longer being held
GVAR(heldKeys) = GVAR(heldKeys) - [_dik];
switch (_dik) do { switch (_dik) do {
case 16: { // Q case 16: { // Q
GVAR(camBoom) = 0; GVAR(camBoom) = 0;

View File

@ -131,8 +131,11 @@
<Key ID="STR_ACE_Spectator_freeCamSpeed"> <Key ID="STR_ACE_Spectator_freeCamSpeed">
<English>Speed Up/Down</English> <English>Speed Up/Down</English>
</Key> </Key>
<Key ID="STR_ACE_Spectator_freeCamVision"> <Key ID="STR_ACE_Spectator_freeCamNextVis">
<English>Toggle Vision Mode</English> <English>Next Vision Mode</English>
</Key>
<Key ID="STR_ACE_Spectator_freeCamPrevVis">
<English>Previous Vision Mode</English>
</Key> </Key>
<Key ID="STR_ACE_Spectator_uiToggleInterface"> <Key ID="STR_ACE_Spectator_uiToggleInterface">