Orion987 1 Posted February 3, 2012 Hello. I am sorry if this has been asked/answered before, but I could not find anything on it. I am trying to run a script when the user presses a certain button (maybe "\" for example). The reason I am not just using addAction to have it on the scroll menu is because it is a respawn script, and it is accidently pressed from time to time, which is very annoying. Is there anyway to map a key to a script? Or is there a way to add it to one of the F1-F8 menus, that would be fine too. The player is not always the squad leader which is why I am not using radio triggers. Please tell me if I left out anything important. Thanks! Share this post Link to post Share on other sites
demonized 20 Posted February 3, 2012 maybe this one is what you need: http://community.bistudio.com/wiki/displaySetEventHandler list of other keys: http://community.bistudio.com/wiki/ListOfKeyCodes 1 Share this post Link to post Share on other sites
twirly 11 Posted February 3, 2012 (edited) Hi... Put this in a file called init.sqf....in your mission folder. This will create a little handler for keypresses. MY_KEYDOWN_FNC = { switch (_this) do { //Key Y case 44: { nul = [] execVM "my_script1.sqf"; }; //Key X case 45: { nul = [] execVM "my_script2.sqf"; }; //Key C case 46: { nul = [] execVM "my_script3.sqf"; }; }; }; To enable your little keypress handler at any time.... //Add an EventHandler to the main display... waituntil {!isnull (finddisplay 46)}; (findDisplay 46) displayAddEventHandler ["KeyDown","_this select 1 call MY_KEYDOWN_FNC;false;"]; Now.. when you press the "Y" key... my_script1.sqf will run. Press the "X" key and my_script2.sqf will run.... and so on..... To remove the EventHandler and return your keyboard to normal.... use.... //Remove the EventHandler... (findDisplay 46) displayRemoveAllEventHandlers "KeyDown"; ASCII Codes can be found here. I believe you have to use the HEX codes.... not 100% sure on that so fiddle to find out. EDIT: I just saw Demonized post above... and think you'd better use the link he posted there to get the Key Codes. As standard ASCII codes are probably not what Arma 2 uses. I have changed the codes in the script above according to that page... so it should now work as posted. Edited February 3, 2012 by twirly Clarity Share this post Link to post Share on other sites
Orion987 1 Posted February 4, 2012 Thank you both very much! I am having one more problem that doesn't really deserve its own thread. I am trying to spawn a module only when a certain variable is true (which is set initially in a unit). I set the variable to true, and in the condition of presence line I put (myVariable). The module doesn't spawn. However, if I put the condition of presence back to true and use hint format to check the variable in the modules init line, the variable returns true. I do not understand why this is not working. Thanks for any help! Share this post Link to post Share on other sites
twirly 11 Posted February 4, 2012 What exactly is in your condition. It should be something like this.... this && myVariable Is the this && there? Share this post Link to post Share on other sites
alleycat 28 Posted March 10, 2013 (edited) Hi...Put this in a file called init.sqf....in your mission folder. This will create a little handler for keypresses. MY_KEYDOWN_FNC = { switch (_this) do { //Key Y case 44: { nul = [] execVM "my_script1.sqf"; }; //Key X case 45: { nul = [] execVM "my_script2.sqf"; }; //Key C case 46: { nul = [] execVM "my_script3.sqf"; }; }; }; To enable your little keypress handler at any time.... //Add an EventHandler to the main display... waituntil {!isnull (finddisplay 46)}; (findDisplay 46) displayAddEventHandler ["KeyDown","_this select 1 call MY_KEYDOWN_FNC;false;"]; Now.. when you press the "Y" key... my_script1.sqf will run. Press the "X" key and my_script2.sqf will run.... and so on..... To remove the EventHandler and return your keyboard to normal.... use.... //Remove the EventHandler... (findDisplay 46) displayRemoveAllEventHandlers "KeyDown"; ASCII Codes can be found here. I believe you have to use the HEX codes.... not 100% sure on that so fiddle to find out. EDIT: I just saw Demonized post above... and think you'd better use the link he posted there to get the Key Codes. As standard ASCII codes are probably not what Arma 2 uses. I have changed the codes in the script above according to that page... so it should now work as posted. You' re da man, you know that, right? Edited March 10, 2013 by alleycat Share this post Link to post Share on other sites
dazholmes 4 Posted December 6, 2015 I tri Hi...Put this in a file called init.sqf....in your mission folder. This will create a little handler for keypresses. MY_KEYDOWN_FNC = { switch (_this) do { //Key Y case 44: { nul = [] execVM "my_script1.sqf"; }; //Key X case 45: { nul = [] execVM "my_script2.sqf"; }; //Key C case 46: { nul = [] execVM "my_script3.sqf"; }; }; }; To enable your little keypress handler at any time.... //Add an EventHandler to the main display... waituntil {!isnull (finddisplay 46)}; (findDisplay 46) displayAddEventHandler ["KeyDown","_this select 1 call MY_KEYDOWN_FNC;false;"]; Now.. when you press the "Y" key... my_script1.sqf will run.Press the "X" key and my_script2.sqf will run.... and so on.....To remove the EventHandler and return your keyboard to normal.... use.... //Remove the EventHandler... (findDisplay 46) displayRemoveAllEventHandlers "KeyDown"; ASCII Codes can be found here.I believe you have to use the HEX codes.... not 100% sure on that so fiddle to find out.EDIT: I just saw Demonized post above... and think you'd better use the link he posted there to get the Key Codes. As standard ASCII codes are probably not what Arma 2 uses. I have changed the codes in the script above according to that page... so it should now work as posted. i know this is an old comment but i'm trying this and it's not working Share this post Link to post Share on other sites