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).
input.press(vk [, ms]) -> boolean, stringPresses 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.
| Name | Type | Default | Description |
|---|---|---|---|
vk | integer | ||
msoptional | number | 30 |
boolean, string
Needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).
events.on("tick", function() input.press(vk.p, 30) end)input.down(vk) -> boolean, stringHolds 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.
| Name | Type | Description |
|---|---|---|
vk | integer |
boolean, string
Needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).
events.on("tick", function() input.down(vk.p) end)input.up(vk) -> boolean, stringReleases this state's hold of a key. Accepted also while actions are blocked (menu open, panic, ...): a release is never refused for the gate.
| Name | Type | Description |
|---|---|---|
vk | integer |
boolean, string
Needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).
events.on("tick", function() input.up(vk.p) end)input.hold(vk, ms) -> boolean, stringHolds a key for ms, clamped 1..2000. Same rules as input.press.
| Name | Type | Description |
|---|---|---|
vk | integer | |
ms | number |
boolean, string
Needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).
events.on("tick", function() input.hold(vk.p, 30) end)input.release_all() -> boolean, stringReleases 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.
boolean, string
Needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).
events.on("tick", function() input.release_all() end)input.is_down(vk) -> booleanKey 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.
| Name | Type | Description |
|---|---|---|
vk | integer |
boolean
if input.is_down(vk.shift) then endinput.pressed(vk) -> booleanKey went down this frame.
| Name | Type | Description |
|---|---|---|
vk | integer |
boolean
if input.pressed(vk.f) then endinput.released(vk) -> booleanKey went up this frame.
| Name | Type | Description |
|---|---|---|
vk | integer |
boolean
if input.released(vk.f) then endinput.mouse() -> number, numberCursor position relative to the game window.
number, number
local mx, my = input.mouse()input.mouse_delta() -> number, numberCursor 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.
number, number
local dx, dy = input.mouse_delta()input.keys_down() -> integer[]Every key and mouse button held now, as virtual-key codes (empty while a menu text field has focus).
integer[]
for _, k in ipairs(input.keys_down()) do log.info(input.key_name(k)) endinput.wheel() -> numberMouse wheel notches this frame.
number
local w = input.wheel()input.menu_open() -> booleanThe evasive menu is open.
boolean
if input.menu_open() then return endinput.key_name(vk) -> stringDisplay name of a key.
| Name | Type | Description |
|---|---|---|
vk | integer |
string
log.info(input.key_name(vk.insert))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.
integer
if input.pressed(vk.f5) then end