Garry's Mod Wiki

input

The input library allows you to gather information about the clients input devices (mouse & keyboard), such as the cursor position and whether a key is pressed or not.

Methods

Returns the last key captured by key trapping.
Returns the digital value of an analog stick on the current (set up via convars) controller.
Returns the cursor's position on the screen. On macOS, the cursor isn't locked on the middle of the screen which causes a significant offset of the positions returned by this function. Issue Tracker: 4964
number input.GetKeyCode( string button )
Gets the button code from a button name. This is opposite of input. GetKeyName.
string input.GetKeyName( number button )
Gets the button name from a numeric button code. The name needs to be translated with language. GetPhrase before being displayed. Despite the name of the function, this also works for the full range of keys in BUTTON_CODE enum.
boolean input.IsButtonDown( number button )
Gets whether the specified button code is down. Unlike input. IsKeyDown this can also detect joystick presses from JOYSTICK enum
Returns whether a control key is being pressed
boolean input.IsKeyDown( number key )
Gets whether a key is down.
Returns whether key trapping is activate and the next key press will be captured.
boolean input.IsMouseDown( number mouseKey )
Gets whether a mouse button is down
Gets whether a shift key is being pressed
string input.LookupBinding( string binding, boolean exact = false )
Returns the client's bound key for the specified console command. If the player has multiple keys bound to a single command, then the key with the lowest BUTTON_CODE enum will be returned.
Returns the bind string that the given key is bound to.
input.SelectWeapon( Weapon weapon )
Switches to the provided weapon on the next CUserCmd generation/CreateMove call. Direct binding to CInput::MakeWeaponSelection.
input.SetCursorPos( number mouseX, number mouseY )
Sets the cursor's position on the screen, relative to the topleft corner of the window
Begins waiting for a key to be pressed so we can save it for input. CheckKeyTrapping. Used by the DBinder.
string input.TranslateAlias( string command )
Translates a console command alias, basically reverse of the alias console command.
Returns whether a key was initially pressed in the same frame this function was called. This function only works in Move hooks, and will detect key presses even in main menu or when a typing in a text field.
Returns whether a key was released in the same frame this function was called. This function only works in Move hooks, and will detect key releases even in main menu or when a typing in a text field.
Returns whether the key is being held down or not. This function only works in Move hooks, and will detect key events even in main menu or when a typing in a text field.
Returns whether a mouse key was double pressed in the same frame this function was called. If this function returns true, input. WasMousePressed will return false. This function only works in Move hooks, and will detect mouse events even in main menu or when a typing in a text field.
Returns whether a mouse key was initially pressed in the same frame this function was called. If input. WasMouseDoublePressed returns true, this function will return false. This function only works in Move hooks, and will detect mouse events even in main menu or when a typing in a text field.
Returns whether a mouse key was released in the same frame this function was called. This function only works in Move hooks, and will detect mouse events even in main menu or when a typing in a text field.