• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit InputKit
19 */
20
21import type { Callback, AsyncCallback } from './@ohos.base';
22import type { KeyCode } from './@ohos.multimodalInput.keyCode';
23
24/**
25 * The input device management module is configured to obtain an ID and device information of an input device.
26 *
27 * @namespace inputDevice
28 * @syscap SystemCapability.MultimodalInput.Input.InputDevice
29 * @since 8
30 */
31declare namespace inputDevice {
32  /**
33   * Add or remove device
34   * @typedef { 'add' | 'remove' }
35   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
36   * @since 9
37   */
38  type ChangedType = 'add' | 'remove';
39
40  /**
41   * The type of input device
42   * @typedef { 'keyboard' | 'mouse' | 'touchpad' | 'touchscreen' | 'joystick' | 'trackball' }
43   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
44   * @since 9
45   */
46  type SourceType = 'keyboard' | 'mouse' | 'touchpad' | 'touchscreen' | 'joystick' | 'trackball';
47
48  /**
49   * Axis Type of the input event
50   * @typedef { 'touchmajor'| 'touchminor' | 'orientation' | 'x' | 'y' | 'pressure' | 'toolminor' | 'toolmajor' | 'null' }
51   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
52   * @since 9
53   */
54  type AxisType =
55    'touchmajor'
56    | 'touchminor'
57    | 'orientation'
58    | 'x'
59    | 'y'
60    | 'pressure'
61    | 'toolminor'
62    | 'toolmajor'
63    | 'null';
64
65  /**
66   * @enum { number }
67   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
68   * @since 9
69   */
70  enum KeyboardType {
71    /**
72     * None
73     *
74     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
75     * @since 9
76     */
77    NONE = 0,
78
79    /**
80     * Unknown key
81     *
82     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
83     * @since 9
84     */
85    UNKNOWN = 1,
86
87    /**
88     * Alphabetical keyboard
89     *
90     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
91     * @since 9
92     */
93    ALPHABETIC_KEYBOARD = 2,
94
95    /**
96     * Digital keyboard
97     *
98     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
99     * @since 9
100     */
101    DIGITAL_KEYBOARD = 3,
102
103    /**
104     * Stylus
105     *
106     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
107     * @since 9
108     */
109    HANDWRITING_PEN = 4,
110
111    /**
112     * Remote control
113     *
114     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
115     * @since 9
116     */
117    REMOTE_CONTROL = 5
118  }
119
120  /**
121   * Defines the listener for input device events.
122   *
123   * @interface DeviceListener
124   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
125   * @since 9
126   */
127  interface DeviceListener {
128    /**
129     * Type of the input device event. The options are add and remove.
130     *
131     * @type { ChangedType }
132     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
133     * @since 9
134     */
135    type: ChangedType;
136
137    /**
138     * ID of the input device for the reported input device event.
139     *
140     * @type { number }
141     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
142     * @since 9
143     */
144    deviceId: number;
145  }
146
147  /**
148   * Starts listening for an input device event.
149   *
150   * @param { 'change' } type - Type of the input device event, which is **change**.
151   * @param { Callback<DeviceListener> } listener - Callback for the input device event.
152   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
153   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
154   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
155   * @since 9
156   */
157  function on(type: 'change', listener: Callback<DeviceListener>): void;
158
159  /**
160   * Stops listening for an input device event.
161   *
162   * @param { 'change' } type - Type of the input device event, which is **change**.
163   * @param { Callback<DeviceListener> } listener - Callback for the input device event.
164   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
165   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
166   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
167   * @since 9
168   */
169  function off(type: 'change', listener?: Callback<DeviceListener>): void;
170
171  /**
172   * Defines axis information about events that can be reported by an input device.
173   * For example, a touchscreen may report information such as x, y, and pressure,
174   * which indicate the x-axis coordinate, y-axis coordinate, and pressure, respectively.
175   *
176   * @interface AxisRange
177   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
178   * @since 8
179   */
180  interface AxisRange {
181    /**
182     * Input source type of the axis. For example, if a mouse reports an x-axis event,
183     * the source of the x-axis is the mouse.
184     *
185     * @type { SourceType }
186     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
187     * @since 8
188     */
189    source: SourceType;
190
191    /**
192     * Type of the axis. for example, the x-axis, y-axis, and pressure axis.
193     *
194     * @type { AxisType }
195     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
196     * @since 8
197     */
198    axis: AxisType;
199
200    /**
201     * Maximum value of the data reported on this axis.
202     *
203     * @type { number }
204     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
205     * @since 8
206     */
207    max: number;
208
209    /**
210     * Minimum value of the data reported on this axis.
211     *
212     * @type { number }
213     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
214     * @since 8
215     */
216    min: number;
217
218    /**
219     * Fuzz value of the data reported on this axis.
220     *
221     * @type { number }
222     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
223     * @since 9
224     */
225    fuzz: number;
226
227    /**
228     * Flat value of the data reported on this axis.
229     *
230     * @type { number }
231     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
232     * @since 9
233     */
234    flat: number;
235
236    /**
237     * Resolution value of the data reported on this axis.
238     *
239     * @type { number }
240     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
241     * @since 9
242     */
243    resolution: number;
244  }
245
246  /**
247   * Defines the information about an input device.
248   *
249   * @interface InputDeviceData
250   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
251   * @since 8
252   */
253  interface InputDeviceData {
254    /**
255     * Id of the input device.
256     *
257     * @type { number }
258     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
259     * @since 8
260     */
261    id: number;
262
263    /**
264     * Name of the input device.
265     *
266     * @type { string }
267     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
268     * @since 8
269     */
270    name: string;
271
272    /**
273     * Source type supported by the input device. For example, if a keyboard is attached with a touchpad,
274     * the device has two input sources: keyboard and touchpad.
275     *
276     * @type { Array<SourceType> }
277     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
278     * @since 8
279     */
280    sources: Array<SourceType>;
281
282    /**
283     * Axis range of the input device.
284     *
285     * @type { Array<AxisRange> }
286     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
287     * @since 8
288     */
289    axisRanges: Array<AxisRange>;
290
291    /**
292     * Bus of the input device.
293     *
294     * @type { number }
295     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
296     * @since 9
297     */
298    bus: number;
299
300    /**
301     * Product of the input device.
302     *
303     * @type { number }
304     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
305     * @since 9
306     */
307    product: number;
308
309    /**
310     * Vendor of the input device.
311     *
312     * @type { number }
313     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
314     * @since 9
315     */
316    vendor: number;
317
318    /**
319     * Version of the input device.
320     *
321     * @type { number }
322     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
323     * @since 9
324     */
325    version: number;
326
327    /**
328     * Physical path of the input device.
329     *
330     * @type { string }
331     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
332     * @since 9
333     */
334    phys: string;
335
336    /**
337     * Unique identifier of the input device.
338     *
339     * @type { string }
340     * @syscap SystemCapability.MultimodalInput.Input.InputDevice
341     * @since 9
342     */
343    uniq: string;
344  }
345
346  /**
347   * Obtains the IDs of all input devices.
348   *
349   * @param { AsyncCallback<Array<number>> } callback - Callback function, receive reported data
350   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
351   * @since 8
352   * @deprecated since 9
353   * @useinstead ohos.multimodalInput.inputDevice#getDeviceList
354   */
355  function getDeviceIds(callback: AsyncCallback<Array<number>>): void;
356
357  /**
358   * Obtains the IDs of all input devices.
359   *
360   * @returns { Promise<Array<number>> }
361   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
362   * @since 8
363   * @deprecated since 9
364   * @useinstead ohos.multimodalInput.inputDevice#getDeviceList
365   */
366  function getDeviceIds(): Promise<Array<number>>;
367
368  /**
369   * Obtain the information about an input device.
370   *
371   * @param { number } deviceId - ID of the input device whose information is to be obtained.
372   * @param { AsyncCallback<InputDeviceData> } callback - Callback function, receive reported data
373   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
374   * @since 8
375   * @deprecated since 9
376   * @useinstead ohos.multimodalInput.inputDevice#getDeviceInfo
377   */
378  function getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): void;
379
380  /**
381   * Obtain the information about an input device.
382   *
383   * @param { number } deviceId - ID of the input device whose information is to be obtained.
384   * @returns { Promise<InputDeviceData> }
385   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
386   * @since 8
387   * @deprecated since 9
388   * @useinstead ohos.multimodalInput.inputDevice#getDeviceInfo
389   */
390  function getDevice(deviceId: number): Promise<InputDeviceData>;
391
392  /**
393   * Obtains the IDs of all input devices.
394   *
395   * @param { AsyncCallback<Array<number>> } callback - Callback function, receive reported data
396   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
397   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
398   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
399   * @since 9
400   */
401  function getDeviceList(callback: AsyncCallback<Array<number>>): void;
402
403  /**
404   * Obtains the IDs of all input devices.
405   *
406   * @returns { Promise<Array<number>> }
407   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
408   * @since 9
409   */
410  function getDeviceList(): Promise<Array<number>>;
411
412  /**
413   * Obtain the information about an input device.
414   *
415   * @param { number } deviceId - ID of the input device whose information is to be obtained.
416   * @param { AsyncCallback<InputDeviceData> } callback - Callback function, receive reported data
417   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
418   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
419   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
420   * @since 9
421   */
422  function getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>): void;
423
424  /**
425   * Obtain the information about an input device.
426   *
427   * @param { number } deviceId - ID of the input device whose information is to be obtained.
428   * @returns { Promise<InputDeviceData> }
429   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
430   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
431   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
432   * @since 9
433   */
434  function getDeviceInfo(deviceId: number): Promise<InputDeviceData>;
435
436  /**
437   * Obtain the information about an input device.
438   *
439   * @param { number } deviceId - ID of the input device whose information is to be obtained.
440   * @returns { InputDeviceData }
441   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
442   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
443   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
444   * @since 10
445   */
446  function getDeviceInfoSync(deviceId: number): InputDeviceData;
447
448  /**
449   * Checks whether the specified key codes of an input device are supported.
450   *
451   * @param { number } deviceId - ID of the input device.
452   * @param { Array<KeyCode> } keys - Key codes of the input device, You can query maximum of five key codes at a time.
453   * @param { AsyncCallback<Array<boolean>> } callback -Indicates whether the specified key codes are supported.
454   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
455   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
456   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
457   * @since 9
458   */
459  function supportKeys(deviceId: number, keys: Array<KeyCode>, callback: AsyncCallback<Array<boolean>>): void;
460
461  /**
462   * Checks whether the specified key codes of an input device are supported.
463   *
464   * @param { number } deviceId - ID of the input device.
465   * @param { Array<KeyCode> } keys - Key codes of the input device, You can query maximum of five key codes at a time.
466   * @returns { Promise<Array<boolean>> } Returns a result indicating whether the specified key codes are supported.
467   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
468   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
469   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
470   * @since 9
471   */
472  function supportKeys(deviceId: number, keys: Array<KeyCode>): Promise<Array<boolean>>;
473
474  /**
475   * Checks whether the specified key codes of an input device are supported.
476   *
477   * @param { number } deviceId - ID of the input device.
478   * @param { Array<KeyCode> } keys - Key codes of the input device, You can query maximum of five key codes at a time.
479   * @returns { Array<boolean> } Returns a result indicating whether the specified key codes are supported.
480   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
481   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
482   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
483   * @since 10
484   */
485  function supportKeysSync(deviceId: number, keys: Array<KeyCode>): Array<boolean>;
486
487  /**
488   * Query the keyboard type of the input device.
489   *
490   * @param { number } deviceId - ID of the specified input device.
491   * @param { AsyncCallback<KeyboardType> } callback - Returns the keyboard type.
492   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
493   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
494   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
495   * @since 9
496   */
497  function getKeyboardType(deviceId: number, callback: AsyncCallback<KeyboardType>): void;
498
499  /**
500   * Query the keyboard type of the input device.
501   *
502   * @param { number } deviceId - ID of the specified input device.
503   * @returns { Promise<KeyboardType> } Returns the keyboard type.
504   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
505   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
506   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
507   * @since 9
508   */
509  function getKeyboardType(deviceId: number): Promise<KeyboardType>;
510
511  /**
512   * Query the keyboard type of the input device.
513   *
514   * @param { number } deviceId - ID of the specified input device.
515   * @returns { KeyboardType } Returns the keyboard type.
516   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
517   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
518   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
519   * @since 10
520   */
521  function getKeyboardTypeSync(deviceId: number): KeyboardType;
522
523  /**
524   * Setting the Keyboard Repetition Delay.
525   *
526   * @param { number } delay - Repeat delay time, the unit is ms.
527   * @param { AsyncCallback<void> } callback - Callback used to return the result.
528   * @throws { BusinessError } 202 - SystemAPI permission error.
529   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
530   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
531   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
532   * @systemapi hide for inner use.
533   * @since 10
534   */
535  function setKeyboardRepeatDelay(delay: number, callback: AsyncCallback<void>): void;
536
537  /**
538   * Setting the Keyboard Repetition Delay.
539   *
540   * @param { number } delay - Repeat delay time, the unit is ms.
541   * @returns { Promise<void> } Returns the result through a promise.
542   * @throws { BusinessError } 202 - SystemAPI permission error.
543   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
544   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
545   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
546   * @systemapi hide for inner use.
547   * @since 10
548   */
549  function setKeyboardRepeatDelay(delay: number): Promise<void>;
550
551  /**
552   * Get the Keyboard Repetition Delay.
553   *
554   * @param { AsyncCallback<number> } callback - Callback used to return the result.
555   * @throws { BusinessError } 202 - SystemAPI permission error.
556   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
557   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
558   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
559   * @systemapi hide for inner use.
560   * @since 10
561   */
562  function getKeyboardRepeatDelay(callback: AsyncCallback<number>): void;
563
564  /**
565   * Get the Keyboard Repetition Delay.
566   *
567   * @returns { Promise<number> } Returns the result through a promise.
568   * @throws { BusinessError } 202 - SystemAPI permission error.
569   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
570   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
571   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
572   * @systemapi hide for inner use.
573   * @since 10
574   */
575  function getKeyboardRepeatDelay(): Promise<number>;
576
577  /**
578   * Setting the Keyboard Key Repetition Rate.
579   *
580   * @param { number } rate - Repetition rate, the unit is ms.
581   * @param { AsyncCallback<void> } callback - Callback used to return the result.
582   * @throws { BusinessError } 202 - SystemAPI permission error.
583   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
584   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
585   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
586   * @systemapi hide for inner use.
587   * @since 10
588   */
589  function setKeyboardRepeatRate(rate: number, callback: AsyncCallback<void>): void;
590
591  /**
592   * Setting the Keyboard Key Repetition Rate.
593   *
594   * @param { number } rate - Repetition rate, the unit is ms.
595   * @returns { Promise<void> } Returns the result through a promise.
596   * @throws { BusinessError } 202 - SystemAPI permission error.
597   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
598   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
599   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
600   * @systemapi hide for inner use.
601   * @since 10
602   */
603  function setKeyboardRepeatRate(rate: number): Promise<void>;
604
605  /**
606   * Get Keyboard Key Repetition Rate.
607   *
608   * @param { AsyncCallback<number> } callback - Callback used to return the result.
609   * @throws { BusinessError } 202 - SystemAPI permission error.
610   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
611   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
612   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
613   * @systemapi hide for inner use.
614   * @since 10
615   */
616  function getKeyboardRepeatRate(callback: AsyncCallback<number>): void;
617
618  /**
619   * Get Keyboard Key Repetition Rate.
620   *
621   * @returns { Promise<number> } Returns the result through a promise.
622   * @throws { BusinessError } 202 - SystemAPI permission error.
623   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
624   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
625   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
626   * @systemapi hide for inner use.
627   * @since 10
628   */
629  function getKeyboardRepeatRate(): Promise<number>;
630
631  /**
632   * Obtains the interval since the last input.
633   *
634   * @returns { Promise<number> } Promise used to return the interval since the last input.
635   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
636   * @since 14
637   */
638  function getIntervalSinceLastInput(): Promise<number>;
639}
640
641export default inputDevice;