evasivedocs
CS2 scriptingLua 5.4.9 · 25 guides · 292 API entries
API reference

Input and keys

Keys, the mouse and the user's CS2 binds.

input

Keyboard and mouse state; with act also key presses (input.press, down, up, hold, release_all).

14 entries

input.press

functionAllow scripts to aim, shoot and press keys
input.press(vk [, ms]) -> boolean, string

Presses a key for ms, clamped 10..200. Pressing a key this state already holds only extends the hold: no new press. vk.mouse1 / vk.mouse2 become attack.fire / attack.secondary; vk.wheel_up / vk.wheel_down send one wheel notch, only while CS2 binds the wheel. Refused: Windows, apps, sleep, F12, browser and media keys ("key"), mouse3..mouse5 without a CS2 bind ("binding"), a chord Alt+Tab / Alt+F4 / Alt+Esc / Ctrl+Alt / Ctrl+Esc with any held key ("chord"), a key the user holds ("physical") or an overlay feature uses ("native"), a key another script holds ("owner"), and past 4 held keys, 2 held modifiers, 8 presses of one key or 20 key edges per second ("rate"). When the user presses a key that would make a system chord with held script keys (Alt+Tab, Ctrl+Esc, Windows+Shift, ...), the script loses its Ctrl, Alt, Shift, Tab, Esc and F4 holds at once; the user's key still reaches CS2.

Arguments
NameTypeDefaultDescription
vkinteger
msoptionalnumber30
Returns
  • boolean, string

Needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).

Example
Lua
events.on("tick", function() input.press(vk.p, 30) end)

input.down

functionAllow scripts to aim, shoot and press keys
input.down(vk) -> boolean, string

Holds a key on a 2 s lease; call it again to renew, input.up to release. input.down(vk.mouse1) is one 200 ms shot, not a hold. Same rules as input.press.

Arguments
NameTypeDescription
vkinteger
Returns
  • boolean, string

Needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).

Example
Lua
events.on("tick", function() input.down(vk.p) end)

input.up

functionAllow scripts to aim, shoot and press keys
input.up(vk) -> boolean, string

Releases this state's hold of a key. Accepted also while actions are blocked (menu open, panic, ...): a release is never refused for the gate.

Arguments
NameTypeDescription
vkinteger
Returns
  • boolean, string

Needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).

Example
Lua
events.on("tick", function() input.up(vk.p) end)

input.hold

functionAllow scripts to aim, shoot and press keys
input.hold(vk, ms) -> boolean, string

Holds a key for ms, clamped 1..2000. Same rules as input.press.

Arguments
NameTypeDescription
vkinteger
msnumber
Returns
  • boolean, string

Needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).

Example
Lua
events.on("tick", function() input.hold(vk.p, 30) end)

input.release_all

functionAllow scripts to aim, shoot and press keys
input.release_all() -> boolean, string

Releases everything this state holds: its keys, its queued or held attack and its aim lease. Accepted also while actions are blocked (menu open, panic, ...): a release is never refused for the gate.

Returns
  • boolean, string

Needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).

Example
Lua
events.on("tick", function() input.release_all() end)

input.is_down

function
input.is_down(vk) -> boolean

Key or mouse button held: any vk.* (false while a menu text field has focus). Sampled once per drawn overlay frame: logic-only ticks see the last sample.

Arguments
NameTypeDescription
vkinteger
Returns
  • boolean
Example
Lua
if input.is_down(vk.shift) then end

input.pressed

function
input.pressed(vk) -> boolean

Key went down this frame.

Arguments
NameTypeDescription
vkinteger
Returns
  • boolean
Example
Lua
if input.pressed(vk.f) then end

input.released

function
input.released(vk) -> boolean

Key went up this frame.

Arguments
NameTypeDescription
vkinteger
Returns
  • boolean
Example
Lua
if input.released(vk.f) then end

input.mouse

function
input.mouse() -> number, number

Cursor position relative to the game window.

Returns
  • number, number
Example
Lua
local mx, my = input.mouse()

input.mouse_delta

function
input.mouse_delta() -> number, number

Cursor movement since the previous overlay frame in pixels. In game cs2 holds the cursor still and reads raw mouse input: use the change of entities.local_player().view_angles for aim movement.

Returns
  • number, number
Example
Lua
local dx, dy = input.mouse_delta()

input.keys_down

function
input.keys_down() -> integer[]

Every key and mouse button held now, as virtual-key codes (empty while a menu text field has focus).

Returns
  • integer[]
Example
Lua
for _, k in ipairs(input.keys_down()) do log.info(input.key_name(k)) end

input.wheel

function
input.wheel() -> number

Mouse wheel notches this frame.

Returns
  • number
Example
Lua
local w = input.wheel()

input.menu_open

function
input.menu_open() -> boolean

The evasive menu is open.

Returns
  • boolean
Example
Lua
if input.menu_open() then return end

input.key_name

function
input.key_name(vk) -> string

Display name of a key.

Arguments
NameTypeDescription
vkinteger
Returns
  • string
Example
Lua
log.info(input.key_name(vk.insert))

vk

Virtual-key codes for input.* and keybinds.

1 entry

vk.insert

constant

Virtual-key codes for every key: a..z, n0..n9 (top row), num0..num9 num_multiply num_add num_separator num_subtract num_decimal num_divide numlock, f1..f24, shift ctrl alt and lshift rshift lctrl rctrl lalt ralt lwin rwin apps, left up right down, insert delete home end_ (or vk["end"]) pageup pagedown, back tab enter escape space capslock scrolllock pause printscreen clear, semicolon equals comma minus period slash grave lbracket backslash rbracket quote oem_102, volume_mute volume_down volume_up media_next media_prev media_stop media_play_pause; mouse buttons lbutton rbutton mbutton xbutton1 xbutton2 (= mouse1..mouse5); wheel_up / wheel_down (not virtual keys: is_down / pressed for a frame with wheel notches that way). Any other code 0x01..0xFE works with input.* too.

Returns
  • integer
Example
Lua
if input.pressed(vk.f5) then end