1# @ohos.multimodalInput.inputDevice (输入设备)(系统接口)
2
3
4输入设备管理模块,用于监听输入设备连接和断开状态,查询输入设备相关信息。
5
6
7> **说明**:
8>
9> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10>
11> 当前页面仅包含模块的系统接口,其他公开接口请参考[@ohos.multimodalInput.inputDevice (输入设备)](js-apis-inputdevice.md)。
12
13
14## 导入模块
15
16```js
17import { inputDevice } from '@kit.InputKit';
18```
19
20## inputDevice.setKeyboardRepeatDelay<sup>10+</sup>
21
22setKeyboardRepeatDelay(delay: number, callback: AsyncCallback&lt;void&gt;): void
23
24设置键盘按键的重复时延,使用AsyncCallback异步方式返回结果。
25
26**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
27
28**系统API**:此接口为系统接口。
29
30**参数**:
31
32| 参数名     | 类型   | 必填 | 说明                                                         |
33| -------- | ------ | ---- | ------------------------------------------------------------ |
34| delay    | number                    | 是    | 键盘按键重复延迟时间,默认值500ms,调节范围[300ms,1000ms]。 |
35| callback | AsyncCallback&lt;void&gt; | 是    | 回调函数。 |
36
37**错误码**:
38
39以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
40
41| 错误码ID  | 错误信息             |
42| ---- | --------------------- |
43| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
44
45**示例**:
46
47```js
48try {
49  inputDevice.setKeyboardRepeatDelay(350, (error: Error) => {
50    if (error) {
51      console.log(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
52      return;
53    }
54    console.log(`Set keyboard repeat delay success`);
55  });
56} catch (error) {
57  console.log(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
58}
59```
60
61## inputDevice.setKeyboardRepeatDelay<sup>10+</sup>
62
63setKeyboardRepeatDelay(delay: number): Promise&lt;void&gt;
64
65设置键盘按键的重复时延,使用Promise异步方式返回结果。
66
67**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
68
69**系统API**:此接口为系统接口。
70
71**参数**:
72
73| 参数名    | 类型     | 必填   | 说明                                  |
74| ----- | ------ | ---- | ----------------------------------- |
75| delay | number | 是    | 键盘按键重复延迟时间,默认值500ms,调节范围[300ms,1000ms]。 |
76
77**返回值**:
78
79| 参数                  | 说明               |
80| ------------------- | ---------------- |
81| Promise&lt;void&gt; | Promise对象。 |
82
83**错误码**:
84
85以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
86
87| 错误码ID  | 错误信息             |
88| ---- | --------------------- |
89| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
90
91**示例**:
92
93```js
94try {
95  inputDevice.setKeyboardRepeatDelay(350).then(() => {
96    console.log(`Set keyboard repeat delay success`);
97  });
98} catch (error) {
99  console.log(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
100}
101```
102
103## inputDevice.getKeyboardRepeatDelay<sup>10+</sup>
104
105getKeyboardRepeatDelay(callback: AsyncCallback&lt;number&gt;): void
106
107获取键盘按键的重复时延,使用AsyncCallback异步方式返回结果。
108
109**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
110
111**系统API**:此接口为系统接口。
112
113**参数**:
114
115| 参数名     | 类型   | 必填 | 说明                                                         |
116| -------- | ------ | ---- | ------------------------------------------------------------ |
117| callback   | AsyncCallback&lt;number&gt;                    | 是    | 回调函数,异步返回键盘按键重复延迟时间。 |
118
119**错误码**:
120
121以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
122
123| 错误码ID  | 错误信息             |
124| ---- | --------------------- |
125| 202  | SystemAPI permission error |
126| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
127
128**示例**:
129
130```js
131try {
132  inputDevice.getKeyboardRepeatDelay((error: Error, delay: Number) => {
133    if (error) {
134      console.log(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
135      return;
136    }
137    console.log(`Get keyboard repeat delay success`);
138  });
139} catch (error) {
140  console.log(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
141}
142```
143
144## inputDevice.getKeyboardRepeatDelay<sup>10+</sup>
145
146getKeyboardRepeatDelay(): Promise&lt;number&gt;
147
148获取键盘按键的重复时延,使用Promise异步方式返回结果。
149
150**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
151
152**系统API**:此接口为系统接口。
153
154**返回值**:
155
156| 参数                    | 说明                  |
157| --------------------- | ------------------- |
158| Promise&lt;number&gt; | Promise实例,异步返回键盘按键的重复时延。 |
159
160**错误码**:
161
162以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
163
164| 错误码ID  | 错误信息             |
165| ---- | --------------------- |
166| 202  | SystemAPI permission error |
167| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
168
169**示例**:
170
171```js
172try {
173  inputDevice.getKeyboardRepeatDelay().then((delay: Number) => {
174    console.log(`Get keyboard repeat delay success`);
175  });
176} catch (error) {
177  console.log(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
178}
179```
180
181## inputDevice.setKeyboardRepeatRate<sup>10+</sup>
182
183setKeyboardRepeatRate(rate: number, callback: AsyncCallback&lt;void&gt;): void
184
185设置键盘按键的重复速率,使用AsyncCallback异步方式返回结果。
186
187**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
188
189**系统API**:此接口为系统接口。
190
191**参数**:
192
193| 参数名     | 类型   | 必填 | 说明                                                         |
194| -------- | ------ | ---- | ------------------------------------------------------------ |
195| rate    | number                    | 是    | 键盘按键重复速率,默认值50ms/次,调节范围[36ms/次,100ms/次]。 |
196| callback | AsyncCallback&lt;void&gt; | 是    | 回调函数。 |
197
198**错误码**:
199
200以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
201
202| 错误码ID  | 错误信息             |
203| ---- | --------------------- |
204| 202  | SystemAPI permission error |
205| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
206
207**示例**:
208
209```js
210try {
211  inputDevice.setKeyboardRepeatRate(60, (error: Error) => {
212    if (error) {
213      console.log(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
214      return;
215    }
216    console.log(`Set keyboard repeat rate success`);
217  });
218} catch (error) {
219  console.log(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
220}
221```
222
223## inputDevice.setKeyboardRepeatRate<sup>10+</sup>
224
225setKeyboardRepeatRate(rate: number): Promise&lt;void&gt;
226
227设置键盘按键的重复速率,使用Promise异步方式返回结果。
228
229**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
230
231**系统API**:此接口为系统接口。
232
233**参数**:
234
235| 参数名    | 类型     | 必填   | 说明                                  |
236| ----- | ------ | ---- | ----------------------------------- |
237| rate | number | 是    | 键盘按键重复速率,默认值50ms/次,调节范围[36ms/次,100ms/次]。 |
238
239**返回值**:
240
241| 参数                  | 说明               |
242| ------------------- | ---------------- |
243| Promise&lt;void&gt; | Promise对象。 |
244
245**错误码**:
246
247以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
248
249| 错误码ID  | 错误信息             |
250| ---- | --------------------- |
251| 202  | SystemAPI permission error |
252| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
253
254**示例**:
255
256```js
257try {
258  inputDevice.setKeyboardRepeatRate(60).then(() => {
259    console.log(`Set keyboard repeat rate success`);
260  });
261} catch (error) {
262  console.log(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
263}
264```
265
266## inputDevice.getKeyboardRepeatRate<sup>10+</sup>
267
268getKeyboardRepeatRate(callback: AsyncCallback&lt;number&gt;): void
269
270获取键盘按键的重复速率,使用AsyncCallback异步方式返回结果。
271
272**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
273
274**系统API**:此接口为系统接口。
275
276**参数**:
277
278| 参数名       | 类型                          | 必填   | 说明             |
279| -------- | --------------------------- | ---- | -------------- |
280| callback | AsyncCallback&lt;number&gt; | 是    | 回调函数,异步返回键盘按键的重复速率。 |
281
282**错误码**:
283
284以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
285
286| 错误码ID  | 错误信息             |
287| ---- | --------------------- |
288| 202  | SystemAPI permission error |
289| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
290
291**示例**:
292
293```js
294try {
295  inputDevice.getKeyboardRepeatRate((error: Error, rate: Number) => {
296    if (error) {
297      console.log(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
298      return;
299    }
300    console.log(`Get keyboard repeat rate success`);
301  });
302} catch (error) {
303  console.log(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
304}
305```
306
307## inputDevice.getKeyboardRepeatRate<sup>10+</sup>
308
309getKeyboardRepeatRate(): Promise&lt;number&gt;
310
311获取键盘按键的重复速率,使用Promise异步方式返回结果。
312
313**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
314
315**系统API**:此接口为系统接口。
316
317**返回值**:
318
319| 参数                    | 说明                  |
320| --------------------- | ------------------- |
321| Promise&lt;number&gt; | Promise实例,异步返回键盘按键的重复速率。 |
322
323**错误码**:
324
325以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
326
327| 错误码ID  | 错误信息             |
328| ---- | --------------------- |
329| 202  | SystemAPI permission error |
330| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
331
332**示例**:
333
334```js
335try {
336  inputDevice.getKeyboardRepeatRate().then((rate: Number) => {
337    console.log(`Get keyboard repeat rate success`);
338  });
339} catch (error) {
340  console.log(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
341}
342```