Jump to content
reggaeman007jah

Custom keys to activate scripts

Recommended Posts

Hello folks,

 

I have been working on some flare scripts for my missions. Basically, I have a few different versions of a simple sqf, that spawn a number of flares around the player. These are useful to me while landing heli’s at night, or getting better visibility of buildings or terrain ahead of my unit while on the ground. Basically, I have a bunch of separate sqf flare scripts, each one used for different purposes (e.g. one provides a circle around the player, another would fire off 5 flares 100m ahead of the player, another keeps repeating flares so that there is constant illumination to counter the very short life-span of vanilla flares etc). 

 

While I can plug these variations of flare-spawns into radio triggers, I would like to try to make a better UI for these sqf’s. I am also keen to activate these variations using voice commands (which are of course just key presses, activated by voice).

 

So, what I am thinking is that I could configure my bank of flare scripts to trigger when I hit a custom key (something random like ctrl + a + 1, ctrl + a + 2 etc). Once these have been set, I can then activate these key combos using Voice Attack, with the result that I can call off a variety of flares using voice alone.

 

 

So, my question to you great and knowledgeable people – how best to do this? Should I explore the CBA keybinds route, or is there a better way?

 

 

Kind regards

RM

Share this post


Link to post
Share on other sites

https://community.bistudio.com/wiki/actionKeys

https://community.bistudio.com/wiki/Category:Key_Actions

https://community.bistudio.com/wiki/DIK_KeyCodes

 

actionKeys can be set to variables.  The key input is a type string, but the actionKey / variable returned is a number.  You can use a switch do statement with conditions equal to the key pressed to make it do something, in theory.  Oh, you will probably need the inputAction command as well.

 

edit: https://community.bistudio.com/wiki/switch

https://community.bistudio.com/wiki/inputAction

 

edit2: in general programming, we use keyListeners to listen out for user input on the keyboard.  Those keys can either return a string or ASCII numerical value.  I personally use switch statements, dependent on situations, to give directives to my program what to do when certain keys are detected by my keyListener.  The switch statement has cases in it that handle the particular key I pressed.  IE: case "k" : { do stuff };  Arma will require you to use their command syntax, however.

 

  • Like 1

Share this post


Link to post
Share on other sites

No problem.  If you need any help, just ask.  Oh, and inputAction is definitely a good starting point.  It's what will drive your program.  Especially keys that are assigned to things that aren't applicable in the situation you are in.  There are crap loads of key assignments in the game.  Not all of them are work while running around as infantry, and not all of them work when you are driving.  Just find one in the area of the keyboard you like that works in cars or planes but not as a foot soldier, or vice versa, and then look up what that assignment is in the Key Actions.

 

https://community.bistudio.com/wiki/inputAction/actions

 

That's for Arma3. 

inputAction "reloadMagazine"

that just happens to be a valid command in game and one of the actions in the list.

 

edit: you can even use the compass or watch key.  It doesn't matter.  Here is an example....

TAG_fn_yourKeyListener = {
	
	while (true) do { 
		if (inputAction "reload" == 1) then {

			//your code

		};
		sleep 1;
	};
	[] spawn TAG_fn_yourKeyListener;
};
[] spawn TAG_fn_yourKeyListener;
//you may have to hold the key down for a second.

 

  • Like 1

Share this post


Link to post
Share on other sites

So, am I right in assuming that I would put the required code into an init.sqf script, as you'd want it triggered from the start of the mission? 

Share this post


Link to post
Share on other sites
On 2/7/2017 at 2:41 AM, Midnighters said:

Input action is executed locally yes?

yes.

 

Player key binds are not broadcasted to the server.  Only resulting actions that are specifically broadcast to the server are not local.

Share this post


Link to post
Share on other sites
12 hours ago, stuguy said:

yes.

 

Player key binds are not broadcasted to the server.  Only resulting actions that are specifically broadcast to the server are not local.

Cool.

thanks.

Share this post


Link to post
Share on other sites
On 3.2.2017 at 1:50 PM, stuguy said:

No problem.  If you need any help, just ask.  Oh, and inputAction is definitely a good starting point.  It's what will drive your program.  Especially keys that are assigned to things that aren't applicable in the situation you are in.  There are crap loads of key assignments in the game.  Not all of them are work while running around as infantry, and not all of them work when you are driving.  Just find one in the area of the keyboard you like that works in cars or planes but not as a foot soldier, or vice versa, and then look up what that assignment is in the Key Actions.

 

https://community.bistudio.com/wiki/inputAction/actions

 

That's for Arma3. 


inputAction "reloadMagazine"

that just happens to be a valid command in game and one of the actions in the list.

 

edit: you can even use the compass or watch key.  It doesn't matter.  Here is an example....


TAG_fn_yourKeyListener = {
	
	while (true) do { 
		if (inputAction "reload" == 1) then {

			//your code

		};
		sleep 1;
	};
	[] spawn TAG_fn_yourKeyListener;
};
[] spawn TAG_fn_yourKeyListener;
//you may have to hold the key down for a second.

 

 

if you're going to use this method use > 0 instead to make it more responsive.

 

also i wouldn't advise spawning the function (certainly not calling i either lol) because using scheduled environment for something that needs reliable instant reaction like a key press is a bad idea. so many ways to slow it down and make it delay and stuff.

 

use this instead: https://community.bistudio.com/wiki/BIS_fnc_loop

 

or similar stuff like stacked frame handlers. aka looping inside non-scheduled environment without halting the main sqf scope.

 

if you are just looking to detect a single key i'd definately use what theend3r posted.

  • Like 1

Share this post


Link to post
Share on other sites

@bad benson thank you mate. I will be honest, much of what you said there is way beyond my knowledge.. but it gives me something to focus on.. so hopefully will make more sense to me in the coming days.

Thanks man

KITD FOHS

Share this post


Link to post
Share on other sites

Hey Reggae, I wanted to contribute with a snip of code I have.  I struggled with actionkeys myself for a while.

 

I use the below implementation to start a jumping script I use in a few missions, but I also use it for triggering a bunch of other things.   As seen below does not tie it to a specific key, but to an action like "inputAction "reloadMagazine"".  It is executed by the client via execvm in initPlayerLocal.sqf.

 

// Main keydown check
keydown_fnc = {
	//This block is ran for every key pressed while in game.  Dont do much (or any) evaluation here.
	//If you already have code for detecting keypresses I reccomend you MOVE lines 15 to 21 there and DELETE lines 63 to 65.
	switch (_this) do {
		{
			case _x: {
				[] spawn ANIM_jump;
			};		
		} foreach (actionkeys "GetOver");  //Handle incoming actionkey DIK codes via foreach, instead of select 0 because some clients may have more than one button for it.

	};
};

//Start the EH to trigger keydown_fnc
waituntil {!isnull (finddisplay 46)};
(findDisplay 46) displayAddEventHandler ["KeyDown","_this select 1 call keydown_fnc;false;"];

 

To add to the actionkeys being searched, use this template.

This example would trigger the function ANIM_jump on every push of the reload button.

Here is a list of all actionkeys. https://community.bistudio.com/wiki/inputAction/actions

{
			case _x: {
				[] spawn ANIM_jump;
			};		
		} foreach (actionkeys "reloadMagazine");

 

 

Use the below if you want to use a single DIK code.   In this case, DIK code 47 is the letter "V".

Use the above if you want to use multiple DIK codes for the same script.  Replace "(actionkeys "reloadMagazine")" with an array of DIK codes. Example "[47,48,49];".

I do not recommend using just the DIK code, because it forces the user to that specific key.  Actionkeys allow your script to read the client's keybinds.


		case 47: {
			[] spawn ANIM_jump;
		};

 

If you want to find a DIK code. Add the below to the first line of the Keydown_fnc.   This will create a hint for every key press while in game.

hint str _this;

 

 

I hope that helped!
 

 

EDIT, this is for using a single key for firing scripts.  The above examples wont handle combo keys like "CTRL + A" as is.

Share this post


Link to post
Share on other sites

@wyattwic This is really helpful mate, thank you, I never would have been able to craft that with my current knowledge levels!

 

I am going to get my head around this over the weekend, hopefully I'll have something useful to report back on..

 

Thanks everyone !! 

Share this post


Link to post
Share on other sites
21 hours ago, reggaeman007jah said:

@wyattwic This is really helpful mate, thank you, I never would have been able to craft that with my current knowledge levels!

 

I am going to get my head around this over the weekend, hopefully I'll have something useful to report back on..

 

Thanks everyone !! 

 

Something I did forget to mention, if you want to detect combos of keys, let me know.  I know I have a code example somewhere.

  • Like 1

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

×