Scripting/Squirrel/Functions/BindKey: Difference between revisions

From Vice City Multiplayer
Jump to navigation Jump to search
Caution icon
This wiki is using an old backup from 2020
Some information may be old/missing
mNo edit summary
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''BindKey''' allows the server to be informed when a player presses a key or a combination of up to three keys.
== Syntax ==
== Syntax ==


<pre>BindKey(press, key, args1, args2)</pre>
<pre>BindKey(press, key1, key2, key3)</pre>


== Arguments ==
== Arguments ==
Line 7: Line 9:
*''bool'' '''press''' - This is the bool for the key function to be called once the key is 'pressed' or 'released'
*''bool'' '''press''' - This is the bool for the key function to be called once the key is 'pressed' or 'released'


*''int'' '''key''' - The key you bind it to, you can get the key codes from [http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx| here]
*''int'' '''key1''' - The primary key you bind it to, you can get the key codes from [https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx here]


*''int'' '''args1''' You can set it to 0
*''int'' '''key2''' - The second key that needs to be pressed for this bind, or zero if not needed.


*''int'' '''args2''' You can set it to 0
*''int'' '''key3''' - The third key that needs to be pressed for this bind, or zero if not needed.


== Example ==
== Example ==
Line 34: Line 36:
=== Notes ===
=== Notes ===


Call [[onScriptLoad]] and [[onKeyDown]] were used in this example. More info about them in the corresponding pages.
* Callbacks [[onScriptLoad]] and [[onKeyDown]] were used in this example. More info about them in the corresponding pages.
* [https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx Virtual Key Codes] — a list of keys and their key codes that can be used for keybinds
 
== Related Functions ==
 
{{Scripting/Squirrel/Functions/Game_Functions}}
[[Category:Scripting/Squirrel/Functions/Game_Functions]]

Latest revision as of 18:05, 30 January 2017

BindKey allows the server to be informed when a player presses a key or a combination of up to three keys.

Syntax

BindKey(press, key1, key2, key3)

Arguments

  • bool press - This is the bool for the key function to be called once the key is 'pressed' or 'released'
  • int key1 - The primary key you bind it to, you can get the key codes from here
  • int key2 - The second key that needs to be pressed for this bind, or zero if not needed.
  • int key3 - The third key that needs to be pressed for this bind, or zero if not needed.

Example

The following example will bind the left-shift key for a player and will send him a message when he player presses that key:

function onScriptLoad()
{
    lshift <- BindKey(true, 0xA0, 0, 0);
}

function onKeyDown( player, key )
{
    if( key == lshift )
    {
        MessagePlayer( ">> You pressed the left shift key", player );
    }
}

Notes

  • Callbacks onScriptLoad and onKeyDown were used in this example. More info about them in the corresponding pages.
  • Virtual Key Codes — a list of keys and their key codes that can be used for keybinds

Related Functions