2022-01-13 10:04:58 +00:00
|
|
|
/*
|
2022-04-27 01:54:45 +00:00
|
|
|
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
2022-01-13 10:04:58 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-04-22 08:13:21 +00:00
|
|
|
import { Callback, AsyncCallback } from "./basic";
|
|
|
|
import { KeyCode } from "./@ohos.multimodalInput.keyCode"
|
2022-01-13 10:04:58 +00:00
|
|
|
|
2022-04-22 08:14:50 +00:00
|
|
|
/**
|
|
|
|
* The input device management module is configured to obtain an ID and device information of an input device.
|
|
|
|
*
|
|
|
|
* @since 8
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @import import inputDevice from '@ohos.multimodalInput.inputDevice';
|
|
|
|
*/
|
2022-01-13 10:04:58 +00:00
|
|
|
|
|
|
|
declare namespace inputDevice {
|
2022-04-24 02:04:35 +00:00
|
|
|
type ChangedType = 'add' | 'remove';
|
|
|
|
|
|
|
|
type SourceType = 'keyboard' | 'mouse' | 'touchpad' | 'touchscreen' | 'joystick' | 'trackball';
|
|
|
|
|
2022-04-24 11:09:08 +00:00
|
|
|
type AxisType = 'touchMajor' | 'touchMinor' | 'orientation' | 'x' | 'y' | 'pressure' | 'toolMinor' | 'touchMajor';
|
2022-04-24 02:04:35 +00:00
|
|
|
|
|
|
|
enum KeyboardType {
|
2022-04-25 06:33:44 +00:00
|
|
|
// 无按键
|
2022-04-24 11:09:08 +00:00
|
|
|
NONE = 0,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 未知按键
|
2022-04-24 11:09:08 +00:00
|
|
|
UNKNOWN = 1,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 字母键盘
|
2022-04-24 11:09:08 +00:00
|
|
|
ALPHABETIC_KEYBOARD = 2,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 数字按键
|
2022-04-24 11:09:08 +00:00
|
|
|
DIGITAL_KEYBOARD = 3,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 手写笔
|
2022-04-24 11:09:08 +00:00
|
|
|
HANDWRITING_PEN = 4,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 遥控器
|
2022-04-24 11:09:08 +00:00
|
|
|
REMOTE_CONTROL = 5,
|
2022-04-25 06:33:44 +00:00
|
|
|
}
|
2022-04-24 02:04:35 +00:00
|
|
|
|
2022-04-24 05:21:01 +00:00
|
|
|
enum PointerStyle {
|
2022-04-25 06:33:44 +00:00
|
|
|
// 正常选择
|
2022-04-24 11:09:08 +00:00
|
|
|
NORMAL_SELECT,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 协助选择
|
2022-04-24 11:09:08 +00:00
|
|
|
HELP_SELECT,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 后台运行
|
2022-04-24 11:09:08 +00:00
|
|
|
WORKING_IN_BACKGROUND,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 忙碌
|
2022-04-24 11:09:08 +00:00
|
|
|
BUSY,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 精确选择
|
2022-04-24 11:09:08 +00:00
|
|
|
PRECISION_SELECT,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 下一步
|
2022-04-24 11:09:08 +00:00
|
|
|
NEXT_SELECT,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 手写
|
2022-04-24 11:09:08 +00:00
|
|
|
HANDWRITING,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 不可用
|
2022-04-24 11:09:08 +00:00
|
|
|
UNAVAILABLE,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 垂直调整
|
2022-04-25 02:03:29 +00:00
|
|
|
VERTICAL_RESIZE,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 水平调整
|
2022-04-24 11:09:08 +00:00
|
|
|
HORIZONTAL_RESIZE,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 正向对角线调整
|
2022-04-24 11:09:08 +00:00
|
|
|
DIAGONAL_RESIZE_1,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 负向对角线调整
|
2022-04-24 11:09:08 +00:00
|
|
|
DIAGONAL_RESIZE_2,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 移动
|
2022-04-24 11:09:08 +00:00
|
|
|
MOVE,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 备选
|
2022-04-24 11:09:08 +00:00
|
|
|
ALTERNATE_SELECT,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 链接
|
2022-04-24 11:09:08 +00:00
|
|
|
LINK_SELECT,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 位置
|
2022-04-24 11:09:08 +00:00
|
|
|
LOCATION_SELECT,
|
2022-04-25 06:33:44 +00:00
|
|
|
|
|
|
|
// 人物
|
2022-04-24 11:09:08 +00:00
|
|
|
PERSON_SELECT,
|
2022-04-27 07:06:48 +00:00
|
|
|
|
|
|
|
// 自定义
|
|
|
|
CUSTOM,
|
2022-04-24 05:21:01 +00:00
|
|
|
}
|
2022-04-24 02:04:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines the listener for input device events.
|
|
|
|
*
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param type Type of the input device event. The options are add and remove.
|
|
|
|
* @param deviceId ID of the input device for the reported input device event.
|
|
|
|
*/
|
|
|
|
interface DeviceListener {
|
|
|
|
(type: ChangedType, deviceId: number): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts listening for an input device event.
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param type Type of the input device event, which is **change**.
|
|
|
|
* @param listener Callback for the input device event.
|
|
|
|
*/
|
|
|
|
function on(type: "change", listener: DeviceListener): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops listening for an input device event.
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param type Type of the input device event, which is **change**.
|
|
|
|
* @param listener Callback for the input device event.
|
|
|
|
*/
|
|
|
|
function off(type: "change", listener?: DeviceListener): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines axis information about events that can be reported by an input device.
|
|
|
|
* For example, a touchscreen may report information such as x, y, and pressure,
|
|
|
|
* which indicate the x-axis coordinate, y-axis coordinate, and pressure, respectively.
|
|
|
|
*
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @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.
|
|
|
|
* @param axis Type of the axis. for example, the x-axis, y-axis, and pressure axis.
|
|
|
|
* @param max Maximum value of the data reported on this axis.
|
|
|
|
* @param min Minimum value of the data reported on this axis.
|
|
|
|
* @param fuzz fuzz value of the data reported on this axis.
|
|
|
|
* @param flat flat value of the data reported on this axis.
|
|
|
|
* @param resolution resolution value of the data reported on this axis.
|
|
|
|
*/
|
|
|
|
interface AxisRange {
|
|
|
|
/**
|
|
|
|
* @since 8
|
|
|
|
*/
|
|
|
|
source: SourceType;
|
2022-04-22 08:13:21 +00:00
|
|
|
|
2022-04-24 02:04:35 +00:00
|
|
|
/**
|
|
|
|
* @since 8
|
|
|
|
*/
|
|
|
|
axis: AxisType;
|
2022-01-13 10:04:58 +00:00
|
|
|
|
2022-04-24 02:04:35 +00:00
|
|
|
/**
|
|
|
|
* @since 8
|
|
|
|
*/
|
|
|
|
max: number;
|
2022-04-20 06:39:46 +00:00
|
|
|
|
2022-04-20 06:30:58 +00:00
|
|
|
/**
|
2022-04-24 02:04:35 +00:00
|
|
|
* @since 8
|
2022-04-20 06:30:58 +00:00
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
min: number;
|
2022-04-20 06:30:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 9
|
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
fuzz: number;
|
2022-04-20 06:30:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 9
|
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
flat: number;
|
2022-04-20 06:30:58 +00:00
|
|
|
|
2022-01-13 10:04:58 +00:00
|
|
|
/**
|
2022-04-24 02:04:35 +00:00
|
|
|
* @since 9
|
|
|
|
*/
|
|
|
|
resolution: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines the information about an input device.
|
|
|
|
*
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param name Name of the input device.
|
|
|
|
* @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.
|
|
|
|
* @param axisRanges
|
|
|
|
* @param bus 总线
|
|
|
|
* @param product 产品
|
|
|
|
* @param vendor 厂商
|
|
|
|
* @param version 版本
|
2022-04-24 11:09:08 +00:00
|
|
|
* @param phys 物理路径
|
|
|
|
* @param uniq 唯一标识符
|
2022-04-24 02:04:35 +00:00
|
|
|
*/
|
|
|
|
interface InputDeviceData {
|
|
|
|
/**
|
|
|
|
* @since 8
|
2022-01-13 10:04:58 +00:00
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
id: number;
|
2022-01-13 10:04:58 +00:00
|
|
|
|
|
|
|
/**
|
2022-04-24 02:04:35 +00:00
|
|
|
* @since 8
|
2022-01-13 10:04:58 +00:00
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
name: string;
|
2022-01-13 10:04:58 +00:00
|
|
|
|
|
|
|
/**
|
2022-04-22 08:13:21 +00:00
|
|
|
* @since 8
|
2022-01-13 10:04:58 +00:00
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
sources: Array<SourceType>;
|
2022-01-13 10:04:58 +00:00
|
|
|
|
|
|
|
/**
|
2022-04-22 08:13:21 +00:00
|
|
|
* @since 8
|
2022-01-13 10:04:58 +00:00
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
axisRanges: Array<AxisRange>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 9
|
|
|
|
*/
|
|
|
|
bus: number;
|
2022-04-20 06:30:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 9
|
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
product: number;
|
2022-04-20 06:39:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 9
|
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
vendor: number;
|
2022-04-20 06:39:46 +00:00
|
|
|
|
|
|
|
/**
|
2022-04-20 06:44:31 +00:00
|
|
|
* @since 9
|
2022-04-20 06:39:46 +00:00
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
version: number;
|
2022-04-20 06:41:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 9
|
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
phys: string;
|
2022-04-20 07:56:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 9
|
|
|
|
*/
|
2022-04-24 02:04:35 +00:00
|
|
|
uniq: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains the IDs of all input devices.
|
|
|
|
*
|
|
|
|
* @since 8
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param callback callback function, receive reported data
|
|
|
|
*/
|
|
|
|
function getDeviceIds(callback: AsyncCallback<Array<number>>): void;
|
|
|
|
function getDeviceIds(): Promise<Array<number>>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain the information about an input device.
|
|
|
|
*
|
|
|
|
* @since 8
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param deviceId ID of the input device whose information is to be obtained.
|
|
|
|
* @param callback callback function, receive reported data
|
|
|
|
*/
|
|
|
|
function getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): void;
|
|
|
|
function getDevice(deviceId: number): Promise<InputDeviceData>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the specified key codes of an input device are supported.
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param deviceId ID of the input device.
|
|
|
|
* @param keys Key codes of the input device. 最多一次查询5个按键码
|
|
|
|
* @return Returns a result indicating whether the specified key codes are supported.
|
|
|
|
*/
|
2022-04-24 11:09:08 +00:00
|
|
|
function supportKeys(deviceId: number, keys: Array<KeyCode>, callback: Callback<Array<boolean>>): void;
|
|
|
|
function supportKeys(deviceId: number, keys: Array<KeyCode>): Promise<Array<boolean>>;
|
2022-04-24 02:04:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 设置光标移动速度
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param speed 光标移动速度。
|
|
|
|
*/
|
2022-04-24 11:09:08 +00:00
|
|
|
function setPointerSpeed(speed: number, callback: AsyncCallback<void>): void;
|
|
|
|
function setPointerSpeed(speed: number): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取光标移动速度
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
*/
|
|
|
|
function getPointerSpeed(callback: AsyncCallback<number>): void;
|
|
|
|
function getPointerSpeed(): Promise<number>;
|
2022-04-24 02:04:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询输入设备的键盘类型
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param deviceId 输入设备标识。
|
|
|
|
* @return 返回键盘类型。
|
|
|
|
*/
|
|
|
|
function getKeyboardType(deviceId: number, callback: AsyncCallback<KeyboardType>): void;
|
|
|
|
function getKeyboardType(deviceId: number): Promise<KeyboardType>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the pointer icon is visible.
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param visible Whether the pointer icon is visible. The value **true** indicates that the pointer icon is visible, and the value **false** indicates the opposite.
|
|
|
|
* @return callback function, receive reported data
|
|
|
|
*/
|
2022-04-27 08:51:25 +00:00
|
|
|
function setPointerVisibility(visible: boolean, callback: AsyncCallback<void>): void;
|
|
|
|
function setPointerVisibility(visible: boolean): Promise<void>;
|
2022-04-24 02:04:35 +00:00
|
|
|
|
2022-04-24 11:09:08 +00:00
|
|
|
/**
|
|
|
|
* 获取光标是否可见
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @return callback function, receive reported data
|
|
|
|
*/
|
|
|
|
function isPointerVisible(callback: AsyncCallback<boolean>): void;
|
|
|
|
function isPointerVisible(): Promise<boolean>;
|
|
|
|
|
2022-04-24 02:04:35 +00:00
|
|
|
/**
|
|
|
|
* 设置鼠标样式
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @param pointerStyle 鼠标样式id。
|
|
|
|
* @return callback function, receive reported data
|
|
|
|
*/
|
2022-04-25 01:25:44 +00:00
|
|
|
function setPointerStyle(pointerStyle: PointerStyle, callback: AsyncCallback<void>): void;
|
|
|
|
function setPointerStyle(pointerStyle: PointerStyle): Promise<void>;
|
2022-04-24 11:09:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取鼠标样式
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.InputDevice
|
|
|
|
* @return callback function, receive reported data
|
|
|
|
*/
|
|
|
|
function getPointerStyle(callback: AsyncCallback<PointerStyle>): void;
|
|
|
|
function getPointerStyle(): Promise<PointerStyle>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 鼠标位置设定
|
|
|
|
*
|
|
|
|
* @since 9
|
|
|
|
* @syscap SystemCapability.MultimodalInput.Input.RemoteInputDevice
|
|
|
|
* @param x x坐标
|
|
|
|
* @param y y坐标
|
|
|
|
* @return -
|
|
|
|
*/
|
|
|
|
function setPointerLocation(x: number, y: number, callback: AsyncCallback<void>): void;
|
|
|
|
function setPointerLocation(x: number, y: number): Promise<void>;
|
2022-01-13 10:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default inputDevice;
|