Jump to content

Recommended Posts

I was searching up how to set up a custom bind that would execute some code. I was able to find code which did exactly what I want it to do with some editing, but I have no idea how any of it works.

The code is this:

waitUntil {!isNull(findDisplay 46)};
(findDisplay 46) displaySetEventHandler ["KeyDown","_this call keyspressed"];

keyspressed = {
    _shift =_this select 2;
    _handled = false;
    switch (_this select 1) do {

    case 35: {//H key
            if (_shift) then {
                player action ["SwitchWeapon", player, player, 100];
            };
        };
    };
    _handled;
};

I generally can read this and understand what it is doing.

This makes it so that when I click shift+h it executes the player action, I can understand the case 35 is the H key with DIK KeyCodes, but how does this script know that you need to press the shift key as well?

Share this post


Link to post
Share on other sites

(on)KeyDown EventHandler will return an array with 5 elements, display, key, shift, ctrl, alt.

And the last 3 values are booleans. In that case, if (_shift) then { }; is detecting the shift.

For more info, go check with some debug commands.

waitUntil {!isNull(findDisplay 46)};
(findDisplay 46) displaySetEventHandler ["KeyDown",{
	systemChat str _this;
}];

 

  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, POLPOX said:

(on)KeyDown EventHandler will return an array with 5 elements, display, key, shift, ctrl, alt.

And the last 3 value is booleans. In that case, if (_shift) then { }; is detecting the shift.

For more info, go check with some debug commands.


waitUntil {!isNull(findDisplay 46)};
(findDisplay 46) displaySetEventHandler ["KeyDown",{
	systemChat str _this;
}];

 

Ah, so _shift is a default value in the game's engine which will always be set for the key SHIFT?

Share this post


Link to post
Share on other sites
Just now, sbondo1234 said:

Ah, so _shift is a default value in the game's engine which will always be set for the key SHIFT?

Yes. Even if you don't press Shift, the _this#2 will always returns the Shift state. Same goes for ctrl(_this#3) and alt(_this#4).

  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, POLPOX said:

Yes. Even if you don't press Shift, the _this#2 will always returns the Shift state. Same goes for ctrl(_this#3) and alt(_this#4).

Thanks a lot! The code makes a lot more sense now!

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

×