Jump to content
MasterPuffin

[Release] Keyhandler with modificators

Recommended Posts

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
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
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
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;
}];

 

  • Like 1

Share this post


Link to post
Share on other sites

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

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

@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
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 :) 

  • Like 1

Share this post


Link to post
Share on other sites
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
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×