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