File: input.md

package info (click to toggle)
surgescript 0.5.4.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,876 kB
  • sloc: ansic: 13,674; makefile: 16
file content (123 lines) | stat: -rw-r--r-- 2,541 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Input
=====

The Input object is used to read input from the user.

*Example*
```
using SurgeEngine.Player;

object "Application"
{
    player = Player.active;

    state "main"
    {
        if(player.input.buttonDown("right"))
            Console.print("User is holding right");
    }
}
```

Factory
-------

#### Input

`Input(inputMap)`

Spawns a new Input component with the given input map.

**Note:** to read input from a specific character, prefer using [Player.input](/engine/player#input) instead.

*Arguments*

* `inputMap`: string. The name of the input map. If set to `null`, a default input map will be used.

*Returns*

An Input component.

*Example*
```
using SurgeEngine.Player;
using SurgeEngine.Input;

object "Application"
{
    input = Player.active.input;         // this form is preferred (used in most cases)
    //input = Input("custom input map"); // unless you need to read a custom input map

    state "main"
    {
        if(input.buttonDown("right"))
            Console.print("User is holding right");
    }
}
```

Properties
----------

#### enabled

`enabled`: boolean.

Whether the input object is enabled or not. A disabled object does not receive user input. The default value of this property is `true`.


Functions
---------

#### buttonDown

`buttonDown(buttonName)`

Checks if a button of the input map is currently being held down.

*Arguments*

* `buttonName`: string. One of the following: *"up", "down", "left", "right", "fire1", "fire2", ..., "fire8"*.

*Returns*

Returns `true` if the specified button is being held down.

#### buttonPressed

`buttonPressed(buttonName)`

Checks if a button has just been pressed.

*Arguments*

* `buttonName`: string. One of the following: *"up", "down", "left", "right", "fire1", "fire2", ..., "fire8"*.

*Returns*

Returns `true` if the specified button has just been pressed.

#### buttonReleased

`buttonReleased(buttonName)`

Checks if a button has just been released.

*Arguments*

* `buttonName`: string. One of the following: *"up", "down", "left", "right", "fire1", "fire2", ..., "fire8"*.

*Returns*

Returns `true` if the specified button has just been released.

#### simulateButton

`simulateButton(buttonName, down)`

Changes the input object so that `buttonName` will be identified as being held down, or not being held down, in the current frame.

*Arguments*

* `buttonName`: string. One of the following: *"up", "down", "left", "right", "fire1", "fire2", ..., "fire8"*.
* `down`: boolean. Should the button be considered as being held down?