Jump to content
Sign in to follow this  
Ranwer135

Detect Certain Key and Does Action?

Recommended Posts

Hey guys,

I have a question that needs to be answered ASAP.

My question is that in Altis Life (non-mod version) you press a specific key on your keyboard and you restrain a player.

Now because that was in a mission folder, how would I do it myself? What I mean is for example, you create a code that will detect a specific key pressed such as the key "P" and does the action.

I hope someone could answer this, It's been bugging me for months even though I do IPT but still can't work it out. :confused:

Kind Regards,

Rawner135 / Ranwer

Share this post


Link to post
Share on other sites

Hi,

I tried your link, I put 35 (which represents the key "H") instead of 45 after findDisplay, and for the code I did an example of: _player1 sideChat "Hello World!";

_player1 has been put as a variable to avoid it to not work, but it somehow it still doesn't work.

Here is my latest code here:

_player1 = this select 0;
moduleName_keyDownEHId = (findDisplay 35) displayAddEventHandler ["KeyDown", "_player1 sideChat "Hello World!";"];

It'll be great If you could spot out what I've done wrong :)

Thanks,

Rawner135 / Ranwer

Share this post


Link to post
Share on other sites
Hi,

I tried your link, I put 35 (which represents the key "H") instead of 45 after findDisplay, and for the code I did an example of: _player1 sideChat "Hello World!";

_player1 has been put as a variable to avoid it to not work, but it somehow it still doesn't work.

Here is my latest code here:

_player1 = this select 0;
moduleName_keyDownEHId = (findDisplay 35) displayAddEventHandler ["KeyDown", "_player1 sideChat "Hello World!";"];

It'll be great If you could spot out what I've done wrong :)

Thanks,

Rawner135 / Ranwer

I assume you called the script via the init-field of a unit. If that's the case, you need to write:

_player1 = _this select 0;

instead of

_player1 = this select 0;

Secondly, findDisplay has nothing to do with the key, it's a command, which finds a display by its idd. To detect userinput one usually uses findDisplay 46 because that's the standard Arma 3 display.

Last but not least, I would suggest to use a code {} instead of a string "".

_player1 = _this select 0;
moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", {_player1 sideChat "Hello World!";}];

The key that has been pressed is then saved in the global variable called moduleName_keyDownEHId, for further use I would suggest to use a easier name.

To call a action after a certain key has been pressed you would need to do something like this:

if (moduleName_keyDownEHId == 3) then 
{

};

Were 3 is your key number.

I hope I could help, don't hesitate to ask further questions.

Share this post


Link to post
Share on other sites

if (moduleName_keyDownEHId == 3) then 
{

};

Were 3 is your key number.

I hope I could help, don't hesitate to ask further questions.

Ahhhh, that's the type of code I was looking for!!! Thanks man!

I'm on my work PC atm now, so I'll report back after testing it on ArmA 3 tomorrow.

Kind Regards,

Rawner135 / Ranwer

---------- Post added at 20:24 ---------- Previous post was at 20:20 ----------

Also, if you can, do you know of a link that has a list of all the numbers that represent a letter, symbol, etc.? And thanks again :D

Share this post


Link to post
Share on other sites
Also, if you can, do you know of a link that has a list of all the numbers that represent a letter, symbol, etc.? And thanks again :D

Here's one list: https://community.bistudio.com/wiki/ListOfKeyCodes

You could also check the numbers by putting this to the code part:

_player1 sideChat str (_this select 1);

and just start hitting different keys.

Share this post


Link to post
Share on other sites

Thanks for the link, will check it out tonight :)

In overall, I'm using the code for my project, which will encourage users to press "H" and whatever weapon they have equiped it will be viewed in animation much like in Counter Strike: Global Offensive. (It mainly gives players a decision wether they should keep the weapon or change it)

Share this post


Link to post
Share on other sites

Does anyone know is it possible to send key presses to client, which he actually didn't press?

Share this post


Link to post
Share on other sites
Does anyone know is it possible to send key presses to client, which he actually didn't press?

Sounds evil. :D

Why would you want that? Make them perform some action?

Share this post


Link to post
Share on other sites
Does anyone know is it possible to send key presses to client, which he actually didn't press?

No need for such "simulations". Just run the scripts/functions that will be activated on those keypresses. Same result, less network load.

I mean, are you trying to visualize keypress? Like, a keyboard button on screen and once it's pressed, it animates (ease-in/out)?

Share this post


Link to post
Share on other sites
Does anyone know is it possible to send key presses to client, which he actually didn't press?

Honey, wheres my "LIKE" button? :don 12:

Share this post


Link to post
Share on other sites
No need for such "simulations". Just run the scripts/functions that will be activated on those keypresses. Same result, less network load.
There is a ton of things you can't do by scripts and can be easily done by pressing one button.

Recent example: player and AI sitting in heli, player is a driver and AI is a gunner. I want to take control (remoteControl) over AI and turn on gunner camera instantly. When you take control over AI using command switchCamera changes view back to player. So you have to move out player from the heli, take control over AI, switch camera, move player back to heli... or just press right mouse button.

Edited by Champ-1

Share this post


Link to post
Share on other sites
There is a ton of things you can't do by scripts and can be easily done by pressing one button.

Recent example: player and AI sitting in heli, player is a driver and AI is a gunner. I want to take control (remoteControl) over AI and turn on gunner camera instantly. When you take control over AI using command switchCamera changes view back to player. So you have to move out player from the heli, take control over AI, switch camera, move player back to heli... or just press right mouse button.

Now that I thought of it in more detail, yeah, there's many possibilities. Like, forcing player into a traffic accident by pulling his vehicle left/right, increasing velocity, etc.

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
Sign in to follow this  

×