Jump to content
Sign in to follow this  
champ-1

keyDown and keyDown issues

Recommended Posts

How to stop display event handler "keyDown" from repeatedly executing script while key is pressed?

Also is it just me or "keyUp" event handler doesn't fire every time? Here's my code:

		[] spawn {
		waitUntil {!isNull findDisplay 46};
		(findDisplay 46) displayAddEventHandler ["keyDown","_this call RE_fnc_keyDown"];
		(findDisplay 46) displayAddEventHandler ["keyUp","_this call RE_fnc_keyUp"];
	};

RE_fnc_keyDown = {
_ctrl = _this select 0;
_dikCode = _this select 1;
_shift = _this select 2;
_ctrlKey = _this select 3;
_alt = _this select 4;

if (!_shift && !_ctrlKey && !_alt && _dikCode in actionKeys "NetworkStats") then {
	nul = [] execVM "scripts\stats.sqf";		
	true
};
};
RE_fnc_keyUp = {
_ctrl = _this select 0;
_dikCode = _this select 1;
_shift = _this select 2;
_ctrlKey = _this select 3;
_alt = _this select 4;

if (!_shift && !_ctrlKey && !_alt && _dikCode in actionKeys "NetworkStats") then {
	hint "";
	true
};
};

"KeyDown" works every time, all the time while the button down. "KeyUp" works only half of the time.

Thanks.

---------- Post added at 22:03 ---------- Previous post was at 22:02 ----------

damn it i messed up the thread name :D

Share this post


Link to post
Share on other sites

I don't know if this is efficient but couldn't you delete the displayeventhandler "keydown" and put it back on "keyup"

Another way might be to use a variable that resets on "keyUP"

RE_fnc_keyDown = {
   _ctrl = _this select 0;
   _dikCode = _this select 1;
   _shift = _this select 2;
   _ctrlKey = _this select 3;
   _alt = _this select 4;

   if  ((player getvariable ["stop",false])) exitwith {};
    player setvariable ["stop",true];

   if (!_shift && !_ctrlKey && !_alt && _dikCode in actionKeys "NetworkStats") then {
        nul = [] execVM "scripts\stats.sqf";  
       true
   };
};

RE_fnc_keyUp = {
   _ctrl = _this select 0;
   _dikCode = _this select 1;
   _shift = _this select 2;
   _ctrlKey = _this select 3;
   _alt = _this select 4;

  player setvariable ["stop",false];
   if (!_shift && !_ctrlKey && !_alt && _dikCode in actionKeys "NetworkStats") then {
      hint "";
       true
   };
};

Share this post


Link to post
Share on other sites

Oh yeah, works like a charm. I guess "keyUp" issue was related to the first problem. Since it works fine now. Thanks, F2k Sel :D

Share this post


Link to post
Share on other sites

Edit: I didn't read f2Sel's whole post, only the first two lines, so my post is kindof the same...

or set a variable.

KeyLocked = false;
(findDisplay 46) displayAddEventHandler ["keyDown",
{
      if (!KeyLocked) then {_this call RE_fnc_keyDown; KeyLocked = true;};
}];

(findDisplay 46) displayAddEventHandler ["keyUp",
{
     _this call RE_fnc_keyUp; KeyLocked = false;
}];

Edited by zapat

Share this post


Link to post
Share on other sites

I think that's a neater approach as it doesn't have to call the function and a little easier on the eye.

Share this post


Link to post
Share on other sites

(findDisplay 46) displayAddEventHandler ["keyDown", {

params ["_ctrl","_dikCode"," _shift","_ctrlKey","_alt"];

if (!_shift && !_ctrlKey && !_alt && _dikCode in actionKeys "NetworkStats") then {([] execVM "scripts\stats.sqf") spawn {waitUntil {inputAction "NetworkStats" == 0}; terminate _this}; true}

}];

this may be a walkaround, not testet and to close dialogs a "terminate" is no option, but you can call a function or something else. the trick is (waitUntil {inputAction "NetworkStats" == 0}).

should work, so God will^^

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×