Page MenuHomeFeedback Tracker

KeyDown UI event handler does not provide correct code for key combination (only single key press)
New, WishlistPublic

Description

For instance, I want to check if player pressed any key (or key combination) that is bound to auto missile locking actions (LockTargets, LockEmptyTargets, VehLockTargets, VehLockEmptyTargets).

So I write a piece of code that starts like this:

  • call BIS_FNC_DISPLAYMISSION displayAddEventHandler

[

		"KeyDown",
		"
			if
			(
				(
					_this select 1 in actionKeys 'LockTargets' or
					{_this select 1 in actionKeys 'LockEmptyTargets'} or
					{_this select 1 in actionKeys 'VehLockTargets'} or
					{_this select 1 in actionKeys 'VehLockEmptyTargets'}
				)
				and
				{

It works if those actions are bound to single key presses, but it doesn't detect 2 or more simultaneous key presses (key combos).

Currently, I want to allow players press the key (or key combo) associated with the 'Custom Control 1' action and with the help of the KeyDown UI event handler detect when the player presses the key or keys and run a script.

Is there a workaround for this? Is it possible to fix this issue?

Thanks

Details

Legacy ID
3731389847
Severity
None
Resolution
Open
Reproducibility
N/A
Category
Scripting

Event Timeline

d3nn16 edited Steps To Reproduce. (Show Details)Sep 21 2014, 11:45 PM
d3nn16 edited Additional Information. (Show Details)
d3nn16 set Category to Scripting.
d3nn16 set Reproducibility to N/A.
d3nn16 set Severity to None.
d3nn16 set Resolution to Open.
d3nn16 set Legacy ID to 3731389847.May 7 2016, 7:28 PM

Custom control 1 would be 'User1'

So you can

inputAction 'User1' > 0

d3nn16 added a subscriber: d3nn16.May 7 2016, 7:28 PM

Thanks for answer.
But I forgot to mention that I also want to disable the default action bound to that key combo. So if a player wants to autolock a target he will see a hint with a message instead of the target lock square/diamond.
Wouldn't it be easier/more performant to make KeyDown event handler detect the key combo like inputAction does?
Is inputAction working reliably inside the KeyDown EH code? I will have to test it (maybe it will work like 50% of the time).

It works fine. What are you going to do if user remapped it from key to mouse button or joystick? AFAIK there is no reliable way to override user input, unless you want to totally disable it.

You cannot block key actions from mouse, joystick, gamepad unfortunately.
There is a A3 FT ticket for that and also one in the A2 CIT.

In regards to key combos - simple ones can be detected, complex ones cant.

My system:
https://dev.withsix.com/projects/push/repository/revisions/master/entry/dev/TM.Limnos/source/scripts/client/KeyDownMainDisplay.sqf
https://dev.withsix.com/projects/push/repository/revisions/master/entry/dev/TM.Limnos/source/scripts/client/sharedCode/keyComboHandling.hpp.sqf

@.kju, login required :(

Problem confirmed.

  1. actionKeys not reliable :

actionKeys can not be used for key combos :

actionKeys "MiniMapToggle" => [39, 4.86539e+008]
39 => ";"
4.86539e+008 <=> "Ctrl + M"

I presume the value contains a binary codification for Ctrl/Alt/Shift. We need at least the scheme of codification on the Biki to handle with it.

  1. Non working solution :

Using (inputAction "MiniMapToggle" > 0) in the KeyDown event handler is not reliable.
If a dialog is opened (like the main map), the value returned by this command is most of time equal to 0.

Repro code of my previous note :

Bind the MiniMapToggle to a single key and a combo key.

Use these keys on the game display (46) :

> The single key is working for actionKeys and inputAction.

> The combo key is NOT working for actionKeys. BUT working for inputAction.

Open the main map (display 12) and do the same test :

> The single key is working for actionKeys. BUT NOT working for inputAction.

> The combo key is NOT working for actionKeys NOR inputAction.

(findDisplay 46) displayAddEventHandler ["KeyDown",
{
systemChat format
[

		"GAME DISPLAY => INPUT : %1 @ KEYS : %2",
		inputAction "MiniMapToggle" > 0,
		(_this select 1) in actionKeys "MiniMapToggle"

];
false
}];
(findDisplay 12) displayAddEventHandler ["KeyDown",
{
systemChat format
[

		"MAP DISPLAY => INPUT : %1 @ KEYS : %2",
		inputAction "MiniMapToggle" > 0,
		(_this select 1) in actionKeys "MiniMapToggle"

];
false
}];

OzDM_Open_CharacterSheet = (findDisplay 46) displayAddEventHandler ["KeyDown", {

_handled = false;
_code = _this select 1;

_shiftState = _this select 2; boolean
_ctrlState = _this select 3;
boolean
_altState = _this select 4; boolean
hintSilent format["This is the code for the key you jsut pressed!!!!! KeyCode: %1", _code];

    switch (_code) do {
        case 199: 
        {
		if (_ctrlState && _altState && _shiftState) then {
			CreateDialog "OzDM_CharacterSheet";
			_handled = true;
			};
		};
    };
    _handled;

}];

Isnt that what the Shift, Ctrl and Alt states are for?

X39 added a subscriber: X39.May 7 2016, 7:28 PM
X39 added a comment.Aug 13 2015, 11:18 PM

keyDown EH works like it should

it is already well known in the community that actionKeys is returning garbage and more as soon as you got anything but single key assigned (you do can have multiple keys set but each of theese have to be single keyed)