Feint 137 Posted March 22, 2015 (edited) So I had this problem with CBA Keys. I wanted to find the assigned keys that the user had changed the keys to and display those assignments in game. This is for the RQ-11B Raven Addon that I’m working on. In the main camera view, there’s a button you can press that will bring up a list of the assigned keys. This is pretty helpful as there are 21 or so assigned keys. Having to hit Esc and drill down into the setup menu to find the name of the key assignment is a PITA. I used to use the command keyName and a userconfig with a bunch of assigned keys that the user could change outside of the game. But since switching to CBA Keys, that command doesn’t work unless you have the key number. I searched around for a function that would give you the key name from CBA Keys but didn’t find one. EDIT: A new version of CBA was just released which includes a function which will tell you the key bind info... [color=#FF8040]MAV_fnc_findCBAKeyAssignments [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b]{[/b][/color] [color=#191970][b]private[/b][/color] [color=#8B3E2F][b][[/b][/color][/color]"_addonToSearchFor","_keyToSearchFor","_keyConfig","_prettyKeyName","_shiftState","_ctrlState","_altState","_assignedKey","_keyResults"[color=#FF8040][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color] [color=#1874CD]_addonToSearchFor[/color] [color=#8B3E2F][b]=[/b][/color] [color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color] [color=#1874CD]_keyToSearchFor[/color] [color=#8B3E2F][b]=[/b][/color] [color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b];[/b][/color] [color=#1874CD]_keyConfig[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_addonToSearchFor[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_keyToSearchFor[/color][color=#8B3E2F][b]][/b][/color] [color=#191970][b]call[/b][/color] cba_fnc_getKeybind[color=#8B3E2F][b];[/b][/color] [color=#1874CD]_prettyKeyName[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_keyConfig[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]2[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color] [color=#1874CD]_shiftState[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_keyConfig[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]5[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color] [color=#1874CD]_ctrlState[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_keyConfig[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]5[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b];[/b][/color] [color=#1874CD]_altState[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_keyConfig[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]5[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]2[/color][color=#8B3E2F][b];[/b][/color] [color=#1874CD]_assignedKey[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]keyName[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_keyConfig[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]5[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b];[/b][/color] [color=#1874CD]_keyResults[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_prettyKeyName[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_shiftState[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_ctrlState[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_altState[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_assignedKey[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color] [color=#1874CD]_keyResults[/color][color=#8B3E2F][b];[/b][/color] [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color][/color] Made with KK's SQF to BBCode Converter So here's how you can use this: For me, I have a keybind set named "RQ-11B Raven Addon". In the Raven keys, I have a key named "Instructions" (default "J"). When people activate the Raven's camera, I want the assigned key to come up on the screen. So this is what I typed: [color=#FF8040][color=#1874CD]_openingCamTextResults[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"RQ-11B Raven Addon"[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"Instructions"[/color][color=#8B3E2F][b]][/b][/color] [color=#191970][b]call[/b][/color] MAV_fnc_findCBAKeyAssignments[color=#8B3E2F][b];[/b][/color] [color=#1874CD]_openingCamText[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]format[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"Press %2%3%4 %5 For %1"[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_openingCamTextResults[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_openingCamTextResults[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_openingCamTextResults[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]2[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_openingCamTextResults[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]3[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_openingCamTextResults[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]4[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color] [color=#191970][b]cutText[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_openingCamText[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]'PLAIN DOWN'[/color][color=#8B3E2F][b],[/b][/color][color=#FF0000]0[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b]; [/b][/color][/color][color=#ff8c00]// RESULT IS: Press "J" For Instructions[/color][color=#FF8040] [/color] Made with KK's SQF to BBCode Converter If I want to find a bunch of key codes, I just do something like this: [color=#FF8040][color=#1874CD]_instructions[/color] [color=#8B3E2F][b]=[/b][/color] [color=#7A7A7A]""[/color][color=#8B3E2F][b];[/b][/color] [color=#8B3E2F][b]{[/b][/color] [color=#1874CD]_testResults[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"RQ-11B Raven Addon"[/color][color=#8B3E2F][b],[/b][/color][color=#000000]_x[/color][color=#8B3E2F][b]][/b][/color] [color=#191970][b]call[/b][/color] MAV_fnc_findCBAKeyAssignments[color=#8B3E2F][b];[/b][/color] [color=#1874CD]_instructions[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_instructions[/color] [color=#8B3E2F][b]+[/b][/color] [color=#7A7A7A]"<br />"[/color] [color=#8B3E2F][b]+[/b][/color] [color=#191970][b]format[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"%1 = %2%3%4 %5"[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_testResults[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_testResults[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_testResults[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]2[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_testResults[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]3[/color][color=#8B3E2F][b],[/b][/color][color=#1874CD]_testResults[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]4[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color] [color=#8B3E2F][b]}[/b][/color] [color=#191970][b]forEach[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"Altitude Raise"[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"Altitude Lower"[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"Radius Increase"[/color][color=#8B3E2F][b],[/b][/color][color=#7A7A7A]"Radius Decrease"[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b]; // RESULT IS FORMATTED TEXT THAT CAN BE DISPLAYED AS: Altitude Raise = W Altitude Lower = S Radius Increase = D Radius Decrease = A [/b][/color][/color] Made with KK's SQF to BBCode Converter Hope you guys find this useful. Edited April 12, 2015 by Feint Share this post Link to post Share on other sites
Feint 137 Posted April 12, 2015 EDIT: Modified first post to update it for new CBA version. Share this post Link to post Share on other sites
-PzGrenBrig37-commy2 10 Posted April 12, 2015 I did something similar in the BWMod (1.2, not released yet) I think you're trying to do something like this: // by commy2 private ["_addon", "_keyName"]; // everything case sensitive _addon = _this select 0; _keyName = _this select 1; private "_registry"; _registry = profileNamespace getVariable ["cba_keybinding_registryNew", [[],[]]]; private "_index"; _index = (_registry select 0) find _addon; if (_index == -1) exitWith {""}; private ["_keyNames", "_keybinds"]; _keyNames = _registry select 1 select _index select 0; _keybinds = _registry select 1 select _index select 1; _index = _keyNames find _keyName; if (_index == -1) exitWith {""}; private "_keybind"; _keybind = _keybinds select _index select 1; // "0 - localized name, 1 - keybind, 2 - default keybind"; private ["_dikCode", "_shift", "_ctrl", "_alt"]; _dikCode = _keybind select 0; _shift = _keybind select 1 select 0; _ctrl = _keybind select 1 select 1; _alt = _keybind select 1 select 2; // init cba key table, to enable it on main menu with disabled mission if (isNil "cba_keybinding_dikDecToStringTable") then { call compile preProcessFileLineNumbers "\x\cba\addons\keybinding\dikDecToString.sqf"; }; private "_keyString"; _keyString = [cba_keybinding_dikDecToStringTable, format ["%1", _dikCode]] call bis_fnc_getFromPairs; if (_shift && {_dikCode != 42}) then { _keyString = format ["Shift+%1", _keyString]; }; if (_alt && {_dikCode != 56}) then { _keyString = format ["Alt+%1", _keyString]; }; if (_ctrl && {_dikCode != 29}) then { _keyString = format ["Ctrl+%1", _keyString]; }; _keyString This is not the right subforum to ask questions though I believe. Share this post Link to post Share on other sites