MasterPuffin 21 Posted February 27, 2017 Hello, since I searched way to long to find a working keyhandler for my mission, I want to share my results with you! ******************************** Put the following code in your init.sqf: execVM "keyhandler.sqf"; in your main mission folder create a file called keyhandler.sqf and put the following code in it waitUntil {!isNull(findDisplay 46)}; (findDisplay 46) displaySetEventHandler ["KeyDown","_this call keyspressed"]; keyspressed = { _keyDik = _this select 1; _shift =_this select 2; _ctrl = _this select 3; _alt = _this select 4; _handled = false; switch (_this select 1) do { case 23: {//I key if (_shift) then { execVM "YOURSCRIPT"; }; if (_ctrl) then { execVM "YOURSCRIPT"; }; }; case 22: {//U key if (_shift) then { execVM "YOURSCRIPT"; }; }; _handled; }; It's pretty self explanatory just replace YOURSCRIPT with the path to your script. The number behind case is the key as shown in this list. If you have any questions feel free to ask! Cheers Puffin Share this post Link to post Share on other sites
serena 151 Posted February 27, 2017 while {isNull(findDisplay 46)} do {sleep 0}; (findDisplay 46) displaySetEventHandler ["KeyDown","call OnKeyDown"]; KeyFunctions = [//dik //shift //ctrl //alt [[23, true, false, false], "YOURSCRIPT1"], // I + Shift [[23, false, true, false], "YOURSCRIPT2"], // I + Ctrl [[22, false, false, false], "YOURSCRIPT3"]];// U OnKeyDown = { private _key = _this select [1, 4]; private _scr = {if (_x select 0 isEqualTo _key) exitWith {_x select 1}} forEach KeyFunctions; if (isNil {_scr}) then {false} else {execVM _scr; true} }; Share this post Link to post Share on other sites
Jack Ost 124 Posted February 27, 2017 Quote Always use displayAddEventHandler instead, as DSetEH overwrites other (peoples') DEH. 1 Share this post Link to post Share on other sites
serena 151 Posted February 27, 2017 KeyFunctions = [//dik //shift //ctrl //alt [[23, true, false, false], "YOURSCRIPT1"], // I + Shift [[23, false, true, false], "YOURSCRIPT2"], // I + Ctrl [[22, false, false, false], "YOURSCRIPT3"]];// U while {isNull(findDisplay 46)} do {sleep 0}; (findDisplay 46) displayAddEventHandler ["KeyDown", { private _key = _this select [1, 4]; private _scr = {if (_x select 0 isEqualTo _key) exitWith {_x select 1}} forEach KeyFunctions; if (isNil {_scr}) then {false} else {execVM _scr; true} }]; Share this post Link to post Share on other sites
serena 151 Posted February 27, 2017 KeyFunctions = [//dik //shift //ctrl //alt [[23, true, false, false], "YOURSCRIPT1"], // I + Shift [[23, false, true, false], "YOURSCRIPT2"], // I + Ctrl [[22, false, false, false], "YOURSCRIPT3"]];// U while {isNull(findDisplay 46)} do {sleep 0}; (findDisplay 46) displayAddEventHandler ["KeyDown", { private _kpd = _this select [1, 4]; {_x params ["_key", "_scr"]; if (_key isEqualTo _kpd) exitWith {execVM _scr; true}; false; } forEach KeyFunctions; }]; 1 Share this post Link to post Share on other sites
Taylor2.0 1 Posted October 18, 2017 hello i do not know alot about this stuff and i made your MP restrain script and i was wondering how to get this to work with it Share this post Link to post Share on other sites
Midnighters 152 Posted October 18, 2017 why not just params it all instead of a wall of selections? not to mention, where are the DIK code inclusion at? Share this post Link to post Share on other sites
MasterPuffin 21 Posted December 8, 2017 @Taylor2.0 Sorry for the late reply buddy, just use the following code: case 22: {//U key if (_shift) then { execVM "scripts/restrain.sqf"; }; In this case it would trigger the script when you press Shift + U Share this post Link to post Share on other sites
Taylor2.0 1 Posted January 5, 2018 On 12/8/2017 at 4:21 PM, MasterPuffin said: @Taylor2.0 Sorry for the late reply buddy, just use the following code: case 22: {//U key if (_shift) then { execVM "scripts/restrain.sqf"; }; In this case it would trigger the script when you press Shift + U Ah ok thank man Thanks for getting back to me it helps :) 1 Share this post Link to post Share on other sites
M.Dimaano 0 Posted April 10, 2023 On 2/28/2017 at 1:25 AM, MasterPuffin said: Hello, since I searched way to long to find a working keyhandler for my mission, I want to share my results with you! ******************************** Put the following code in your init.sqf: execVM "keyhandler.sqf"; in your main mission folder create a file called keyhandler.sqf and put the following code in it waitUntil {!isNull(findDisplay 46)}; (findDisplay 46) displaySetEventHandler ["KeyDown","_this call keyspressed"]; keyspressed = { _keyDik = _this select 1; _shift =_this select 2; _ctrl = _this select 3; _alt = _this select 4; _handled = false; switch (_this select 1) do { case 23: {//I key if (_shift) then { execVM "YOURSCRIPT"; }; if (_ctrl) then { execVM "YOURSCRIPT"; }; }; case 22: {//U key if (_shift) then { execVM "YOURSCRIPT"; }; }; _handled; }; Having a problem with "line 4 in the keyspressed = {" part. It says that it's missing a } and I don't know where to put. So far that's the part that makes it not work on my end. Share this post Link to post Share on other sites
RCA3 593 Posted April 11, 2023 7 hours ago, M.Dimaano said: Having a problem with "line 4 in the keyspressed = {" part. It says that it's missing a } and I don't know where to put. So far that's the part that makes it not work on my end. Add one more }; to the end (below everything). Share this post Link to post Share on other sites