Jump to content
Sign in to follow this  
chronicsilence

Determining all actions bound to a given key

Recommended Posts

Using the "actionKeys" command, I can get a list of all keys bound to the given action. Does anyone know of a way to do the opposite, i.e. to get all the actions bound to a given key?

Share this post


Link to post
Share on other sites

Don't think there's a built-in command for this.

though, you can make a workaround. just prototyping below.

- get arrays of Dik codes for all actions of a unit

- compare arrays of Dik codes, find the repeating codes, mark them

- check the source of the marked arrays

- determine if the 'source' is your actionName

- return a new array of Dik codes for a given action

Share this post


Link to post
Share on other sites

Mmm Dik codes are unreliable due to rounding errors for multikey commands e.g...

Ctrl + space (HC commanding mode)

actionKeys "switchCommand"

[4.86539e+008]

actionKeysNames "switchCommand"

"Left Ctrl+Space"

keyname ((actionkeys "switchcommand") select 0)

""Left Ctrl+F6"" ????? EH

Closest i could get was something like this....

fnc_getKeyActions = {
private [ "_key", "_keyActions", "_name", "_action", "_actionKeysString", "_multi", "_foundKey" ];

_key = switch ( typeName _this ) do {
	case (  typeName 0 ) : {
		_name = toLower ( keyName _this );
		_name = _name select [ 1, ( count _name ) -2 ];
		_name
	};
	case ( typeName "" ) : {
		toLower _this
	};
	default {
		nil
	};
};

if ( isNil "_key" ) exitWith {[]};

_keyActions = [];
"
	{
		_action = _x;
		{
			_actionKeysString = tolower _x;
			if ( count _actionKeysString > 0 ) then {
				if ( count _actionKeysString isequalto 1 && { _key isEqualTo _actionKeysString } ) then {
					_keyActions pushback _action;
				}else{
					_multi = _actionKeysString find '2x';
					if ( _multi > -1 ) then {
						_actionKeysString = toArray _actionKeysString;
						_actionKeysString deleteRange [ _multi, 2 ];
						_actionKeysString = toString _actionKeysString;
					};
					_actionKeysString = [ _actionKeysString, '+' ] call BIS_fnc_splitString;
					{
						_foundKey = _x;
						if ( _foundKey isEqualTo _key ) then {
							_keyActions pushBack _action;
						};
					}foreach _actionKeysString;
				};
			};
		}foreach actionKeysNamesArray _action;
	}forEach getArray ( _x >> 'group' );
"configClasses ( configFile >> "UserActionGroups" );

_keyActions
};

Pass in either a Dik code (dec or hex) or key name (with correct spacing e.g "Left Ctrl") and it will pass back an array of all commands the key is used for. It breaks multi key commands down so searching "Left Ctrl" will return commands that are say "Left Ctrl+E" etc.

Not sure if there is maybe a better way to do this or even if my code is 100% correct but from a few test it looks ok.

Edited by Larrow
sured up function

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  

×