Jump to content
Sign in to follow this  
maxqubit

Bind a key directly to a script

Recommended Posts

You either can have a dialog (meaning a full interface with buttons, you cant aim but have a mouse-pointer instead) or you have a resource => meaning the mouse-events are not caught and you can still aim. I guess you cant catch mouse-events when the mouse is not trapped in a dialog.

Ask weedomatic, maybe he got some experience with mouseevents unter ressourcese.

Share this post


Link to post
Share on other sites

Source: (BI-wiki page)

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_control displaySetEventHandler ["KeyDown", ""]

Using two scripts:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

//init.sqf start

keyspressed = compile preprocessFile "keyspressed.sqf";

_display = findDisplay 46;

_display displaySetEventHandler ["KeyDown","_this call keyspressed"];

//init.sqf end

//keyspressed.sqf start

switch((_this select 1))do

{

   //F key

   case 33:

   {

      // What to do ...

   };

};

//keyspressed.sqf end

Some key-codes are also provided on the page above.

Edit: Don't know if this will work with mouse-events -- haven't tested.

Share this post


Link to post
Share on other sites

Does someone have a simple example of a keypress script inside a mission they could post (i.e., post the mission, not code snippets)?

I just tried what weedomatic suggested (which is straight from the biki), and it isn't working for me. I understand that it is two separate scripts (init.sqf and keyspressed.sqf), but nothing happens when I press any key. I added a hint in the 33 case condition, and added another hint at the top of keyspressed.sqf to see if it ever got into the function at all (it didn't).

So I am perplexed...

Share this post


Link to post
Share on other sites

Just tested it in a mission with code from this thread and the wiki-page. Mission contains init.sqf and keyspressed.sqf, code follows:

init.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">keyspressed = compile preprocessFile "keyspressed.sqf";

sleep 0.5; // Display needs to init itself, so we give it time

if(!IsNull (findDisplay 46)) then {(findDisplay 46) displaySetEventHandler ["KeyDown","_this call keyspressed"];};

keyspressed.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// If you want something to be done on

// any key:

// hint "SOME KEY PRESSED!";

switch((_this select 1))do

{

// Reacts to "F" key only

case 33:

{

hint "F KEY PRESSED!";

};

};

Without putting the init.sqf to sleep for a moment, it wouldn't find the display. May be my machine, don't know.

Share this post


Link to post
Share on other sites

Weed,

Thanks alot, the sleep delay made it work!

This will be very useful.

JB

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  

×