Jump to content
colinm9991

Disable Key Press / Input

Recommended Posts

So this works, but if the users holds any button and THEN presses the button which has "Select All" binded to; it opens without issue.

How do I fix this so that it doesn't open the "SelectAll" menu regardless of how many button the person holds before pressing the actual keybind

if (isNull player) exitwith {};
KEY_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 "SelectAll") then {
	hint "Disabled";
	true 
}; 
}; 

KEY_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 "SelectAll") then { 
	hint "Disabled"; 
	true 
}; 
};

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

Edited by ColinM9991

Share this post


Link to post
Share on other sites

Scratch what I said, misread part of your post.

Share this post


Link to post
Share on other sites
Scratch what I said, misread part of your post.

Looks like I was just a bit too late in reading your comment, I have updated my main post however to correct some of my own mistakes.

Share this post


Link to post
Share on other sites

You aren't allowed to bump on these forums, at all.

So don't do it.

Share this post


Link to post
Share on other sites

Where does it say that? The rules page says nothing about Bumping being against the rules.

Also before you say it's classified as "Spam".

§5) No Spam

We deem spam as making a thread or posting a reply that has no real worth, is irrelevant, useless and offers nothing to a discussion. Posting "any news" or "is it out yet" type posts are also spam. Messages of banned members are also considered as spam. If your post/thread is not able to illicit or sustain an in depth conversation then it's spam. This also applies to other areas of the forums such as leaving visitor messages on people's profiles. Spam may be dealt with by post count reduction, Post Restriction and/or formal warning.

Edited by ColinM9991

Share this post


Link to post
Share on other sites

I guess you are trying to force the player to stop before execute the key combination.

If you you could check the speed of the players unit.

Share this post


Link to post
Share on other sites
I guess you are trying to force the player to stop before execute the key combination.

If you you could check the speed of the players unit.

I want the players to continue as they are doing; I just want to detect multiple keystrokes.

If I press Right Windows, it does nothing.

If I hold W (W is an example, it works for any random key held before hand) and then press Right Windows, it opens the Select All Panel.

I want to make it so Right Windows does nothing, Holding W (Random Key) and pressing Right Windows does nothing; or holding any number of keys and pressing Right Windows does nothing.

Share this post


Link to post
Share on other sites

I'm not sure if "SelectAll" is valid.

example this blocks the Crouch key "X" and it still works if other keys are pressed at the same time, however in A2 it was "CROUCH" not "MOVEUP"

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

if (_dikCode in actionKeys "moveup") then {

	 hint "Disabled1";
	true 
}; 
};

however "SelectAll" has no effect even if it's the only key pressed , if you look for the number returned it's huge and not in the normal range of keyboard number.

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

if (_dikCode in actionKeys "SELECTALL") then {
	 hint "Disabled1";
	true 	
}; 
}; 

I think they've have played with the codes but not published a list.

this seems to work if I'm understanding you right. There is still one combination of keys that gets around it but I can't work out the combination.

if (isNull player) exitwith {};
KEY_fnc_keyDown = { 
_ctrl = _this select 0; 
_dikCode = _this select 1; 
_shift = _this select 2; 
_ctrlKey = _this select 3; 
_alt = _this select 4; 
if ((!_shift or !_ctrlKey or !_alt) and _dikCode in actionKeys "ForceCommandingMode") then {
	hint "Disabled Down";
	true 
}; 
}; 

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


if ((!_shift or !_ctrlKey or !_alt) and _dikCode in actionKeys "ForceCommandingMode") then { 
	hint "Disabled Up"; 
	true 
}; 
};


waitUntil {!isNull findDisplay 46}; 
(findDisplay 46) displayAddEventHandler ["keyDown","_this call KEY_fnc_keyDown"];
(findDisplay 46) displayAddEventHandler ["keyUp","_this call KEY_fnc_keyUp"];

Edited by F2k Sel

Share this post


Link to post
Share on other sites

this seems to work if I'm understanding you right. There is still one combination of keys that gets around it but I can't work out the combination.

if (isNull player) exitwith {};
KEY_fnc_keyDown = { 
_ctrl = _this select 0; 
_dikCode = _this select 1; 
_shift = _this select 2; 
_ctrlKey = _this select 3; 
_alt = _this select 4; 
if ((!_shift or !_ctrlKey or !_alt) and _dikCode in actionKeys "ForceCommandingMode") then {
	hint "Disabled Down";
	true 
}; 
}; 

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


if ((!_shift or !_ctrlKey or !_alt) and _dikCode in actionKeys "ForceCommandingMode") then { 
	hint "Disabled Up"; 
	true 
}; 
};


waitUntil {!isNull findDisplay 46}; 
(findDisplay 46) displayAddEventHandler ["keyDown","_this call KEY_fnc_keyDown"];
(findDisplay 46) displayAddEventHandler ["keyUp","_this call KEY_fnc_keyUp"];

Hi there!

I've been trying the above code to disable the "keyUp" event on the W key : this would, in my idea, make the engine consider that this key is being hold, allowing the player to keep walking/running without actually holding the key.

(findDisplay 46) displayAddEventHandler ["keyUp", "_this call functionName_keytest"];

functionName_keytest = {
private ["_handled", "_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
_ctrl = _this select 0;
_dikCode = _this select 1;
_shift = _this select 2;
_ctrlKey = _this select 3;
_alt = _this select 4;

if (_dikCode == 17 && {!_shift && !_ctrlKey && !_alt}) then {
	true
};
};

I'm trying to achieve something similar to Cyprus AutoWalk mod, but by toggling a key input On and Off.

The problem is that the override doesn't seem to work with "KeyUp" - eventhough it does work with a "KeyDown" eventhandler (the key is successfully disabled and the player can't move forward anymore).

Is this an issue with the "KeyUp" EH, or are they meant to work differently?

Share this post


Link to post
Share on other sites

Pepe Hal

I expect the issue is that movement commands are sent when/while key down fires. Attempting to disable key up doesn't mean that key down will continue uninterrupted when you release the key.

Technically, you've overriden any events set by the engine to trigger on key up by using your own handler. You haven't actually prevented the key up event from firing, you've just changed what happens.

Releasing the key means the key down state is no longer true, ie the key code is no longer being sent. All irrespective of what happens in key up.

Share this post


Link to post
Share on other sites

Releasing the key means the key down state is no longer true, ie the key code is no longer being sent. All irrespective of what happens in key up.

Hi Cyprus!

Thanks for the input - how did I not think of that! ^^'

I guess there's no way to simulate a key input/hold then, not with scripts at least... :(

Share this post


Link to post
Share on other sites

Use your EH to toggle a continuous playAction.

Share this post


Link to post
Share on other sites
Use your EH to toggle a continuous playAction.

That's more or less the solution Cyprus went for; but it requires a lot of scripting to have something working right.

I wanted to try and see if something simpler was possible; the above method doesn't involve much except for a couple EH, and it would have several advantages other Cyprus' way (I mean no disrepect to Cyprus mod! It is an outstanding piece of work! ;) ).

The player would be able to keep a good control other his avatar (switch stances while moving, change pace without interrupting the "auto-walk", etc...). Basically it could work in pretty much all situations without the need to check for various and complicated conditions. :)

If only I could make it work... ^^

Share this post


Link to post
Share on other sites

Indeed. I did try various mechanisms but playActionNow was really the only method that worked properly.

It wasn't that overly complicated either, but it did break the engine mechanics - hence my comments in the readme about game exploits and me putting in all the extra checks to prevent them.

No offense taken btw, I agree with everything you said on retaining more fluid movement. In fact, I had played with some code to allow just that (sideways movement, stepping over etc) and it worked ok-ish but seemed to eat frames so i removed it. I wrote the whole thing in two sittings, and just wanted to release before my vacation. I'll have another go at it in a few weeks when I'm back.

Btw, could you share some more detail on when you say changing pace interrupts the auto walk, please? If I need to fix something then I'd like to know more.

Thanks :)

Share this post


Link to post
Share on other sites

Btw, could you share some more detail on when you say changing pace interrupts the auto walk, please? If I need to fix something then I'd like to know more.

Thanks :)

Did some tests and I think it was just me hitting the wrong key... ^^'

I'll PM you if I stumble upon any issues! ;)

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

×