Game controllers script functions¶
Functions for C# (Cb.Call) and Python (cb.call). See Script functions for how to use them.
controllers.get¶
Finds one game controller and tells you about it. Starts watching controllers if needed.
| Value | What to put in |
|---|---|
controller |
Optional. Which controller: a slot like "#1", part of its name, its type (like "PS5") or its GUID. Default "#1". |
Gives back: The controller's details (name, slot, type, battery, held buttons, axes, hats), or null when none matches.
var answer = await Cb.Call("controllers.get", new { controller = "#1" });
answer = cb.call("controllers.get", controller="#1")
controllers.learn¶
Waits for you to press a button, move a stick or push the d-pad, then tells you what it was. Handy for finding a button's name.
| Value | What to put in |
|---|---|
timeoutMs |
Optional. How long to wait, in milliseconds (100 to 300000). Default 10000 (10 seconds). |
controller |
Optional. Only listen to this controller (slot like "#1", name, type or GUID). Leave it out to listen to all. |
Gives back: What was pressed: kind, name, label, controller (its details), triggerType, settings and description. null when nothing was pressed in time.
var answer = await Cb.Call("controllers.learn", new { timeoutMs = 15000 });
answer = cb.call("controllers.learn", timeoutMs=15000)
controllers.list¶
Lists the game controllers that are plugged in right now. Starts watching controllers if it was not already. Fails with an error when controller input is turned off.
Gives back: A list of controllers. Each has its name, slot number, type, battery, held buttons, axes (stick and trigger values) and hats (d-pad directions).
var answer = await Cb.Call("controllers.list");
answer = cb.call("controllers.list")
controllers.reloadMappings¶
Reads the controller mappings file (gamecontrollerdb.txt) again, so new controller types are known. Fails with an error when there is no such file.
Gives back: How many mappings were added. 0 when controller input is not running yet (the file is read when it starts).
var answer = await Cb.Call("controllers.reloadMappings");
answer = cb.call("controllers.reloadMappings")
controllers.rumble¶
Makes a game controller shake (rumble). Fails with an error when controller input is turned off.
| Value | What to put in |
|---|---|
controller |
Optional. Which controller: a slot like "#1", part of its name, its type or GUID. Several can be split with commas. Default "Any" (all of them). |
low |
Optional. Strength of the big, slow motor, 0-100 percent. Default 50. |
high |
Optional. Strength of the small, fast motor, 0-100 percent. Default 50. |
durationMs |
Optional. How long to shake, in milliseconds (1000 = 1 second, at most 60000). Default 500. |
Gives back: How many controllers shook.
var answer = await Cb.Call("controllers.rumble", new { controller = "#1", low = 80, high = 80, durationMs = 1000 });
answer = cb.call("controllers.rumble", controller="#1", low=80, high=80, durationMs=1000)
controllers.setLed¶
Changes the light colour on game controllers that have one, like a PlayStation controller. Fails with an error when the colour cannot be read.
| Value | What to put in |
|---|---|
controller |
Optional. Which controller: a slot like "#1", part of its name, its type or GUID. Default "Any" (all of them). |
color |
The colour as "#RRGGBB" (like "#FF0000" for red) or "r,g,b" (like "255,0,0"). |
Gives back: How many controllers changed colour.
var answer = await Cb.Call("controllers.setLed", new { color = "#9146FF" });
answer = cb.call("controllers.setLed", color="#9146FF")
controllers.status¶
Tells you whether game controller input is running and how.
Gives back: running (true/false), backend (the controller library in use), version, state, message (a status line) and mode (the watch setting from the Controllers page).
var answer = await Cb.Call("controllers.status");
answer = cb.call("controllers.status")