Page MenuHomeFeedback Tracker

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

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
Won't Fix
Reproducibility
N/A
Operating System
Windows 7
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)

dedmen added a subscriber: dedmen.Jun 3 2020, 3:19 PM

New alternatives to actionKeys are on my roadmap, we'll see if that actually happens.
actionKeys itself will not/cannot be fixed.

dedmen closed this task as Resolved.Jun 3 2020, 3:19 PM
dedmen updated the task description. (Show Details)
dedmen changed Resolution from Open to Won't Fix.
dedmen edited Steps To Reproduce. (Show Details)
dedmen edited Additional Information. (Show Details)
dedmen set Operating System to Windows 7.
BIS_fnc_KK reopened this task as Assigned.
BIS_fnc_KK raised the priority of this task from Wishlist to Normal.

rev 148523, added alt syntax actionKeys [action] https://community.bistudio.com/wiki/actionKeys

BIS_fnc_KK removed BIS_fnc_KK as the assignee of this task.Nov 21 2021, 12:18 PM
BIS_fnc_KK changed the task status from Assigned to Feedback.
BIS_fnc_KK added a subscriber: BIS_fnc_KK.

new actionKeys alt syntax doesn't solve this issue (EventHandler still provides number as argument which you cannot check here still)

But for actual ticket:

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).

you can use https://community.bistudio.com/wiki/addUserActionEventHandler instead of using actionKeys/keyDown handler.

johnb43 added a subscriber: johnb43.EditedFeb 18 2022, 7:01 PM

I like the new syntax of actionKeys. It makes some things previous impossible possible. However I have a request:

Unfortunately there is no way to reliably compare big numbers in Arma itself - which is something I personally need what I have in mind.
I need to be able to convert a decimal number into it's hexadecimal representation, in order to compare it to these criteria.

The only way to do that right now is to have an Extension do the conversion from a decimal in String format to a hexadecimal in String format (e.g "487784725" ->"1D130115" or "277" -> "00000115"). (My Extension currently doesn't account for negative values, because I didn't think it was possible - but apparently Right Alt + Z does so (I'm guessing overflow?). That can be rectified however - but it's not the point I'm trying to convey.)

So my request is to add an optional argument to actionKeys to return the keybinds in 8 byte hexadecimal representation in a String.
Unsure about the "0x" prefix being needed - but I don't think it would hurt. It can be easily filtered and removed using String commands.

actionKeys ["ReloadMagazine", true]

This would make input comparison much easier.

Can open another ticket with this request if wanted.

I have a plan for actionKeysEx which just returns the flags as an array, for which modifiers are pressed and stuff.
That way you don't need to handle big numbers at all

As actionKeysEx was added, imo this is resolved (it does the job well for me).