跳转至

Input

继承

Object

简要描述

处理输入的单例。

描述

处理输入的单例。这包含了按键按下,鼠标按键移动,输入动作。动作跟他们的时间可以被设置在工程设置中的Input Map

方法

返回值类型 方法名称
void action_press(action: String, strength: float = 1.0)
void action_release(action: String)
void add_joy_mapping(mapping: String, update_existing: bool = false)
Vector3 get_accelerometer() const
float get_action_strength(action: String) const
Array get_connected_joypads()
int get_current_cursor_shape() const
Vector3 get_gravity() const
Vector3 get_gyroscope() const
float get_joy_axis(device: int, axis: int) const
int get_joy_axis_index_from_string(axis: String)
String get_joy_axis_string(axis_index: int)
int get_joy_button_index_from_string(button: String)
String get_joy_button_string(button_index: int)
String get_joy_guid(device: int) const
String get_joy_name(device: int)
float get_joy_vibration_duration(device: int)
Vector2 get_joy_vibration_strength(device: int)
Vector2 get_last_mouse_speed() const
Vector3 get_magnetometer() const
int get_mouse_button_mask() const
int get_mouse_mode() const
bool is_action_just_pressed(action: String) const
bool is_action_just_released(action: String) const
bool is_action_pressed(action: String) const
bool is_joy_button_pressed(device: int, button: int) const
bool is_joy_known(device: int)
bool is_key_pressed(scancode: int) const
bool is_mouse_button_pressed(button: int) const
void joy_connection_changed(device: int, connected: bool, name: String, guid: String)
void parse_input_event(event: InputEvent)
void remove_joy_mapping(guid: String)
void set_custom_mouse_cursor(image: Resource, shape: int = 0, hotspot: Vector2 = Vector2( 0, 0 ))
void set_default_cursor_shape(shape: int = 0)
void set_mouse_mode(mode: int)
void set_use_accumulated_input(enable: bool)
void start_joy_vibration(device: int, weak_magnitude: float, strong_magnitude: float, duration: float = 0)
void stop_joy_vibration(device: int)
void vibrate_handheld(duration_ms: int = 500)
void warp_mouse_position(to: Vector2)

信号

  • joy_connection_changed

连接或断开游戏手柄设备时发出。


枚举

enum MouseMode: - MOUSE_MODE_VISIBLE = 0

如果鼠标光标处于隐藏状态,则使其可见。

  • MOUSE_MODE_HIDDEN = 1

如果可见,将鼠标光标隐藏。

  • MOUSE_MODE_CAPTURED = 2

捕获鼠标。鼠标将不能被隐藏,不能离开游戏窗体,但是仍然注册移动按钮事件。在windows,linux中,鼠标会使用raw input模式,这意味着鼠标移动不受OS设置影响。

  • MOUSE_MODE_CONFINED = 3

使鼠标光标可见,但将其限制在游戏窗口中。


enum CursorShape: - CURSOR_ARROW = 0

箭头光标。标准默认鼠标。

  • CURSOR_IBEAM = 1

工字形光标。表示这里有文字。

  • CURSOR_POINTING_HAND = 2

指向手形光标。表示这里是一个链接或者可交互的。

  • CURSOR_CROSS = 3

十字光标。出现在当可以进行画操作时。

  • CURSOR_WAIT = 4

等待光标。表示程序正忙。

  • CURSOR_BUSY = 5

繁忙的光标。表示程序正忙。

  • CURSOR_DRAG = 6

拖动光标。表示可以拖动。

  • CURSOR_CAN_DROP = 7

可以放下光标。表示拖动的东西可以放下。

  • CURSOR_FORBIDDEN = 8

禁止光标。表示拖动的东西此处不能放下。

  • CURSOR_VSIZE = 9

垂直调整鼠标光标。表示可以垂直调整窗体大小。

  • CURSOR_HSIZE = 10

水平调整鼠标光标。表示可以水平调整窗体大小。

  • CURSOR_BDIAGSIZE = 11

窗口调整鼠标光标。表示可以调整窗体大小。

  • CURSOR_FDIAGSIZE = 12

窗口调整鼠标光标。表示可以调整窗体大小。

  • CURSOR_MOVE = 13

移动光标。表示可以移动物体。

  • CURSOR_VSPLIT = 14

垂直拆分鼠标光标。windows上与 CURSOR_VSIZE一样。

  • CURSOR_HSPLIT = 15

水平拆分鼠标光标。windows上与 CURSOR_HSIZE一样。

  • CURSOR_HELP = 16

帮助光标。通常是一个问好。


方法说明

  • action_press action_press(action: String, strength: float = 1.0)

这将模拟按下指定的动作。

该强度可用于非布尔型动作,其范围在0到1之间,代表给定动作的强度。

**注意:**此方法将不会导致任何[方法Node._input]调用。


  • action_release action_release(action: String)

如果已经按了指定的操作,则将其释放。


  • add_joy_mapping add_joy_mapping(mapping: String, update_existing: bool = false)

将新的映射条目(SDL2格式)添加到映射数据库。


  • get_accelerometer get_accelerometer() const

如果设备具有加速度计,它将返回加速度。

请注意,即使您的设备具有加速度计,从编辑器运行时,此方法也会返回空的Vector3


  • get_action_strength get_action_strength(action: String) const

返回介于0和1之间的值,代表给定动作的强度。在joypad中,越远的轴是远离dead区域的,靠近的值是1。


  • get_connected_joypads get_connected_joypads()

返回一个Array,其中包含所有当前连接的游戏手柄的设备ID。


  • get_current_cursor_shape get_current_cursor_shape() const

返回当前分配的光标形状(请参见[枚举CursorShape])。


  • get_gravity get_gravity() const

如果设备具有加速度计,这将返回重力。


  • get_gyroscope get_gyroscope() const

如果设备带有陀螺仪,它将返回围绕设备X,Y和Z轴的弧度旋转速率。否则返回空。


  • get_joy_axis get_joy_axis(device: int, axis: int) const

返回给定索引处的游戏手柄轴的当前值(请参见JoystickList)。


  • get_joy_axis_index_from_string get_joy_axis_index_from_string(axis: String)

返回提供的轴名称的索引。


  • get_joy_axis_string get_joy_axis_string(axis_index: int)

接收JoystickList轴并以字符串形式返回其等效名称。


  • get_joy_button_index_from_string get_joy_button_index_from_string(button: String)

返回提供的按钮名称的索引。


  • get_joy_button_string get_joy_button_string(button_index: int)

从[枚举JoystickList]接收游戏手柄按钮,并以字符串形式返回其等效名称。


  • get_joy_guid get_joy_guid(device: int) const

在使用游戏手柄重新映射的平台上返回与SDL2兼容的设备GUID。否则返回Default Gamepad。


  • get_joy_name get_joy_name(device: int)

返回指定设备索引处的游戏手柄名称。


  • get_joy_vibration_duration get_joy_vibration_duration(device: int)

以秒为单位返回当前振动效果的持续时间。


  • get_joy_vibration_strength get_joy_vibration_strength(device: int)

返回操纵板振动的强度:x是弱电机的强度,而y是强电机的强度。


  • get_last_mouse_speed get_last_mouse_speed() const

返回上一次光标移动的鼠标速度,此速度直到鼠标移动到下一帧为止。这意味着如果鼠标没有移动,仍然会返回上一次鼠标位置的值。


  • get_magnetometer get_magnetometer() const

如果设备具有磁力计,则将返回所有轴的微特斯拉磁场强度。


  • get_mouse_button_mask get_mouse_button_mask() const

返回鼠标按钮作为位掩码。如果多个鼠标按键被同时按下,则bits会被叠加在一起。


  • get_mouse_mode get_mouse_mode() const

返回鼠标模式。


  • is_action_just_pressed is_action_just_pressed(action: String) const

当用户开始按下动作事件时,返回true,这意味着仅在用户按下按钮的帧上它才是true

这对于在按下某个动作时只需要运行一次,而不是在按下某帧时只运行一次的代码很有用。


  • is_action_just_released is_action_just_released(action: String) const

当用户停止按下动作事件时,返回true,这意味着仅在用户释放按钮的帧上才是true


  • is_action_pressed is_action_pressed(action: String) const

如果您按下动作事件,则返回true。注意如果一个动作已经有多个按键被使用的并且不只一个被按下了,释放一个按键会释放对应的动作,即使当前还有其它按键按下。


  • is_joy_button_pressed is_joy_button_pressed(device: int, button: int) const

如果按下操纵杆按钮,则返回true(请参阅JoystickList)。


  • is_joy_known is_joy_known(device: int)

如果系统知道指定的设备,则返回true。这意味着设置所有的按键跟轴与定义的一致。未知的joypads人然可以获取事件。


  • is_key_pressed is_key_pressed(scancode: int) const

如果按该键,则返回true


  • is_mouse_button_pressed is_mouse_button_pressed(button: int) const

如果您按下由ButtonList指定的鼠标按钮,则返回true


  • joy_connection_changed joy_connection_changed(device: int, connected: bool, name: String, guid: String)

通知Input单例连接已更改,以更新device索引的状态。

这是内部使用的,不必从用户脚本中调用。


  • parse_input_event parse_input_event(event: InputEvent)

向游戏提供InputEvent

例:

var a = InputEventAction.new()
a.action = ui_cancel
a.pressed = true
Input.parse_input_eventa

  • remove_joy_mapping remove_joy_mapping(guid: String)

从内部数据库中删除与给定GUID匹配的所有映射。


  • set_custom_mouse_cursor set_custom_mouse_cursor(image: Resource, shape: int = 0, hotspot: Vector2 = Vector2( 0, 0 ))

设置自定义鼠标光标图像,该图像仅在游戏窗口内可见。

图片的大小必须小于256×256。

hotspot的大小必须在image的范围内。

**注意:**不支持AnimatedTexture作为自定义鼠标光标。

注意:**仅支持以**无损,**有损**或**未压缩**压缩模式导入的图像。


  • set_default_cursor_shape set_default_cursor_shape(shape: int = 0)

设置要在视口中使用的默认光标形状,而不是CURSOR_ARROW

**注意:**如果要更改Control节点的默认光标形状,请改用Control.mouse_default_cursor_shape

**注意:**此方法生成一个InputEventMouseMotion以立即更新光标。


  • set_mouse_mode set_mouse_mode(mode: int)

设置鼠标模式。


  • set_use_accumulated_input set_use_accumulated_input(enable: bool)

是否累积操作系统发送的类似输入事件。


  • start_joy_vibration start_joy_vibration(device: int, weak_magnitude: float, strong_magnitude: float, duration: float = 0)

开始振动游戏手柄。

**注意:**并非每种硬件都具有长效期。


  • stop_joy_vibration stop_joy_vibration(device: int)

停止游戏手柄的振动。


  • vibrate_handheld vibrate_handheld(duration_ms: int = 500)

振动Android和iOS设备。

**注意:**导出设置需要Android的VIBRATE权限。


  • warp_mouse_position warp_mouse_position(to: Vector2)

将鼠标位置设置为指定的向量。