• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2021-2022 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 { Callback, AsyncCallback } from "./basic";
17import { 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 * @since 8
23 * @syscap SystemCapability.MultimodalInput.Input.InputDevice
24 */
25declare namespace inputDevice {
26  /**
27   * @since 9
28   */
29  type ChangedType = 'add' | 'remove';
30
31  /**
32   * @since 9
33   */
34  type SourceType = 'keyboard' | 'mouse' | 'touchpad' | 'touchscreen' | 'joystick' | 'trackball';
35
36  /**
37   * @since 9
38   */
39  type AxisType = 'touchMajor' | 'touchMinor' | 'orientation' | 'x' | 'y' | 'pressure' | 'toolMinor' | 'toolMajor' | 'NULL';
40
41  /**
42   * @since 9
43   */
44  enum KeyboardType {
45    /**
46     * None
47     */
48    NONE = 0,
49
50    /**
51     * Unknown key
52     */
53    UNKNOWN = 1,
54
55    /**
56     * Alphabetical keyboard
57     */
58    ALPHABETIC_KEYBOARD = 2,
59
60    /**
61     * Digital keyboard
62     */
63    DIGITAL_KEYBOARD = 3,
64
65    /**
66     * Stylus
67     */
68    HANDWRITING_PEN = 4,
69
70    /**
71     * Remote control
72     */
73    REMOTE_CONTROL = 5,
74  }
75
76  /**
77   * Defines the listener for input device events.
78   *
79   * @since 9
80   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
81   * @param type Type of the input device event. The options are add and remove.
82   * @param deviceId ID of the input device for the reported input device event.
83   */
84  interface DeviceListener {
85    type: ChangedType;
86    deviceId: number;
87  }
88
89  /**
90   * Starts listening for an input device event.
91   *
92   * @since 9
93   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
94   * @param type Type of the input device event, which is **change**.
95   * @returns Callback for the input device event.
96   * @throws {BusinessError} 401 - Parameter error.
97   */
98  function on(type: "change", listener: Callback<DeviceListener>): void;
99
100  /**
101   * Stops listening for an input device event.
102   *
103   * @since 9
104   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
105   * @param type Type of the input device event, which is **change**.
106   * @returns Callback for the input device event.
107   * @throws {BusinessError} 401 - Parameter error.
108   */
109  function off(type: "change", listener?: Callback<DeviceListener>): void;
110
111  /**
112   * Defines axis information about events that can be reported by an input device.
113   * For example, a touchscreen may report information such as x, y, and pressure,
114   * which indicate the x-axis coordinate, y-axis coordinate, and pressure, respectively.
115   *
116   * @since 8
117   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
118   * @param source Input source type of the axis. For example, if a mouse reports an x-axis event, the source of the x-axis is the mouse.
119   * @param axis Type of the axis. for example, the x-axis, y-axis, and pressure axis.
120   * @param max Maximum value of the data reported on this axis.
121   * @param min Minimum value of the data reported on this axis.
122   * @param fuzz Fuzz value of the data reported on this axis.
123   * @param flat Flat value of the data reported on this axis.
124   * @param resolution Resolution value of the data reported on this axis.
125   */
126  interface AxisRange {
127    /**
128     * @since 8
129     */
130    source: SourceType;
131
132    /**
133     * @since 8
134     */
135    axis: AxisType;
136
137    /**
138     * @since 8
139     */
140    max: number;
141
142    /**
143     * @since 8
144     */
145    min: number;
146
147    /**
148     * @since 9
149     */
150    fuzz: number;
151
152    /**
153     * @since 9
154     */
155    flat: number;
156
157    /**
158     * @since 9
159     */
160    resolution: number;
161  }
162
163  /**
164   * Defines the information about an input device.
165   *
166   * @since 8
167   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
168   * @param name Name of the input device.
169   * @param sources Source type supported by the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad.
170   * @param axisRanges Axis range of the input device.
171   * @param bus Bus of the input device.
172   * @param product Product of the input device.
173   * @param vendor Vendor of the input device.
174   * @param version Version of the input device.
175   * @param phys Physical path of the input device.
176   * @param uniq Unique identifier of the input device.
177   */
178  interface InputDeviceData {
179    /**
180     * @since 8
181     */
182    id: number;
183
184    /**
185     * @since 8
186     */
187    name: string;
188
189    /**
190     * @since 8
191     */
192    sources: Array<SourceType>;
193
194    /**
195     * @since 8
196     */
197    axisRanges: Array<AxisRange>;
198
199    /**
200     * @since 9
201     */
202    bus: number;
203
204    /**
205     * @since 9
206     */
207    product: number;
208
209    /**
210     * @since 9
211     */
212    vendor: number;
213
214    /**
215     * @since 9
216     */
217    version: number;
218
219    /**
220     * @since 9
221     */
222    phys: string;
223
224    /**
225     * @since 9
226     */
227    uniq: string;
228  }
229
230  /**
231   * Obtains the IDs of all input devices.
232   *
233   * @since 8
234   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
235   * @param callback Callback function, receive reported data
236   * @deprecated since 9
237   * @useinstead ohos.multimodalInput.inputDevice#getDeviceList
238   */
239  function getDeviceIds(callback: AsyncCallback<Array<number>>): void;
240
241  /**
242   * Obtains the IDs of all input devices.
243   *
244   * @since 8
245   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
246   * @deprecated since 9
247   * @useinstead ohos.multimodalInput.inputDevice#getDeviceList
248   */
249  function getDeviceIds(): Promise<Array<number>>;
250
251  /**
252   * Obtain the information about an input device.
253   *
254   * @since 8
255   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
256   * @param deviceId ID of the input device whose information is to be obtained.
257   * @param callback Callback function, receive reported data
258   * @deprecated since 9
259   * @useinstead ohos.multimodalInput.inputDevice#getDeviceInfo
260   */
261  function getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): void;
262
263  /**
264   * Obtain the information about an input device.
265   *
266   * @since 8
267   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
268   * @param deviceId ID of the input device whose information is to be obtained.
269   * @deprecated since 9
270   * @useinstead ohos.multimodalInput.inputDevice#getDeviceInfo
271   */
272  function getDevice(deviceId: number): Promise<InputDeviceData>;
273
274  /**
275   * Obtains the IDs of all input devices.
276   *
277   * @since 9
278   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
279   * @param callback Callback function, receive reported data
280   * @throws {BusinessError} 401 - Parameter error.
281   */
282  function getDeviceList(callback: AsyncCallback<Array<number>>): void;
283
284  /**
285   * Obtains the IDs of all input devices.
286   *
287   * @since 9
288   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
289   */
290  function getDeviceList(): Promise<Array<number>>;
291
292  /**
293  * Obtain the information about an input device.
294  *
295  * @since 9
296  * @syscap SystemCapability.MultimodalInput.Input.InputDevice
297  * @param deviceId ID of the input device whose information is to be obtained.
298  * @param callback Callback function, receive reported data
299  * @throws {BusinessError} 401 - Parameter error.
300  */
301  function getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>): void;
302
303  /**
304  * Obtain the information about an input device.
305  *
306  * @since 9
307  * @syscap SystemCapability.MultimodalInput.Input.InputDevice
308  * @param deviceId ID of the input device whose information is to be obtained.
309  * @throws {BusinessError} 401 - Parameter error.
310  */
311  function getDeviceInfo(deviceId: number): Promise<InputDeviceData>;
312
313  /**
314   * Checks whether the specified key codes of an input device are supported.
315   *
316   * @since 9
317   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
318   * @param deviceId ID of the input device.
319   * @param keys Key codes of the input device, You can query a maximum of five key codes at a time.
320   * @returns Returns a result indicating whether the specified key codes are supported.
321   * @throws {BusinessError} 401 - Parameter error.
322   */
323  function supportKeys(deviceId: number, keys: Array<KeyCode>, callback: AsyncCallback<Array<boolean>>): void;
324
325  /**
326   * Checks whether the specified key codes of an input device are supported.
327   *
328   * @since 9
329   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
330   * @param deviceId ID of the input device.
331   * @param keys Key codes of the input device, You can query a maximum of five key codes at a time.
332   * @returns Returns a result indicating whether the specified key codes are supported.
333   * @throws {BusinessError} 401 - Parameter error.
334   */
335  function supportKeys(deviceId: number, keys: Array<KeyCode>): Promise<Array<boolean>>;
336
337  /**
338   * Query the keyboard type of the input device.
339   *
340   * @since 9
341   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
342   * @param deviceId ID of the specified input device.
343   * @returns Returns the keyboard type.
344   * @throws {BusinessError} 401 - Parameter error.
345   */
346  function getKeyboardType(deviceId: number, callback: AsyncCallback<KeyboardType>): void;
347
348  /**
349   * Query the keyboard type of the input device.
350   *
351   * @since 9
352   * @syscap SystemCapability.MultimodalInput.Input.InputDevice
353   * @param deviceId ID of the specified input device.
354   * @returns Returns the keyboard type.
355   * @throws {BusinessError} 401 - Parameter error.
356   */
357  function getKeyboardType(deviceId: number): Promise<KeyboardType>;
358}
359
360export default inputDevice;