W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
輸入設備管理模塊,用于監(jiān)聽輸入設備連接和斷開狀態(tài),查詢輸入設備相關信息。
本模塊首批接口從API version 8開始支持。后續(xù)版本的新增接口,采用上角標單獨標記接口的起始版本。
getDeviceList(callback: AsyncCallback<Array<number>>): void
獲取所有輸入設備的id列表,使用AsyncCallback異步方式返回結(jié)果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<Array<number>> | 是 | 回調(diào)函數(shù),異步返回所有輸入設備的id列表。 |
示例:
- try {
- inputDevice.getDeviceList((error, ids) => {
- if (error) {
- console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
- return;
- }
- console.log(`Device id list: ${JSON.stringify(ids)}`);
- });
- } catch (error) {
- console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
getDeviceList(): Promise<Array<number>>
獲取所有輸入設備的id列表,使用Promise異步方式返回結(jié)果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
返回值:
參數(shù) | 說明 |
---|---|
Promise<Array<number>> | Promise對象,異步返回所有輸入設備的id列表。 |
示例:
- try {
- inputDevice.getDeviceList().then((ids) => {
- console.log(`Device id list: ${JSON.stringify(ids)}`);
- });
- } catch (error) {
- console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>): void
獲取指定輸入設備的信息,使用AsyncCallback異步方式返回結(jié)果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
deviceId | number | 是 | 輸入設備id。 |
callback | AsyncCallback<InputDeviceData> | 是 | 回調(diào)函數(shù),異步返回輸入設備信息。 |
示例:
- // 獲取輸入設備id為1的設備信息。
- try {
- inputDevice.getDeviceInfo(1, (error, deviceData) => {
- if (error) {
- console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
- return;
- }
- console.log(`Device info: ${JSON.stringify(deviceData)}`);
- });
- } catch (error) {
- console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
getDeviceInfo(deviceId: number): Promise<InputDeviceData>
獲取指定輸入設備的信息,使用Promise異步方式返回結(jié)果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
deviceId | number | 是 | 輸入設備id。 |
返回值:
參數(shù) | 說明 |
---|---|
Promise<InputDeviceData> | Promise對象,異步返回輸入設備信息。 |
示例:
- // 獲取輸入設備id為1的設備信息。
- try {
- inputDevice.getDeviceInfo(1).then((deviceData) => {
- console.log(`Device info: ${JSON.stringify(deviceData)}`);
- });
- } catch (error) {
- console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
on(type: "change", listener: Callback<DeviceListener>): void
監(jiān)聽輸入設備的熱插拔事件,使用時需連接鼠標鍵盤等外部設備。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 輸入設備的事件類型。 |
listener | Callback<DeviceListener> | 是 | 回調(diào)函數(shù),異步上報輸入設備熱插拔事件。 |
示例:
- let isPhysicalKeyboardExist = true;
- try {
- inputDevice.on("change", (data) => {
- console.log(`Device event info: ${JSON.stringify(data)}`);
- inputDevice.getKeyboardType(data.deviceId, (err, type) => {
- console.log("The keyboard type is: " + type);
- if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
- // 監(jiān)聽物理鍵盤已連接。
- isPhysicalKeyboardExist = true;
- } else if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
- // 監(jiān)聽物理鍵盤已斷開。
- isPhysicalKeyboardExist = false;
- }
- });
- });
- // 根據(jù)isPhysicalKeyboardExist的值決定軟鍵盤是否彈出。
- } catch (error) {
- console.log(`Get device info failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
off(type: "change", listener?: Callback<DeviceListener>): void
取消監(jiān)聽輸入設備的熱插拔事件。在應用退出前調(diào)用,取消監(jiān)聽。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 輸入設備的事件類型。 |
listener | Callback<DeviceListener> | 否 | 取消監(jiān)聽的回調(diào)函數(shù)。 |
示例:
- function callback(data) {
- console.log(`Report device event info: ${JSON.stringify(data, [`type`, `deviceId`])}`);
- };
- try {
- inputDevice.on("change", callback);
- } catch (error) {
- console.log(`Listen device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
- // 取消指定的監(jiān)聽。
- try {
- inputDevice.off("change", callback);
- } catch (error) {
- console.log(`Cancel listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
- // 取消所有監(jiān)聽。
- try {
- inputDevice.off("change");
- } catch (error) {
- console.log(`Cancel all listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
getDeviceIds(callback: AsyncCallback<Array<number>>): void
獲取所有輸入設備的id列表,使用AsyncCallback異步方式返回結(jié)果。
從API version 9 開始不再維護,建議使用inputDevice.getDeviceList代替。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<Array<number>> | 是 | 回調(diào)函數(shù),異步返回所有輸入設備的id列表。 |
示例:
- inputDevice.getDeviceIds((error, ids) => {
- if (error) {
- console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
- return;
- }
- console.log(`Device id list: ${JSON.stringify(ids)}`);
- });
getDeviceIds(): Promise<Array<number>>
獲取所有輸入設備的id列表,使用Promise異步方式返回結(jié)果。
從API version 9 開始不再維護,建議使用inputDevice.getDeviceList代替。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
返回值:
參數(shù) | 說明 |
---|---|
Promise<Array<number>> | Promise對象,異步返回所有輸入設備的id列表。 |
示例:
- inputDevice.getDeviceIds().then((ids) => {
- console.log(`Device id list: ${JSON.stringify(ids)}`);
- });
getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): void
獲取指定輸入設備的信息,使用AsyncCallback異步方式返回結(jié)果。
從API version 9 開始不再維護,建議使用inputDevice.getDeviceInfo代替。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
deviceId | number | 是 | 輸入設備id。 |
callback | AsyncCallback<InputDeviceData> | 是 | 回調(diào)函數(shù),異步返回輸入設備信息。 |
示例:
- // 獲取輸入設備id為1的設備信息。
- inputDevice.getDevice(1, (error, deviceData) => {
- if (error) {
- console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
- return;
- }
- console.log(`Device info: ${JSON.stringify(deviceData)}`);
- });
getDevice(deviceId: number): Promise<InputDeviceData>
獲取指定輸入設備的信息,使用Promise異步方式返回結(jié)果。
從API version 9 開始不再維護,建議使用inputDevice.getDeviceInfo代替。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
deviceId | number | 是 | 輸入設備id。 |
返回值:
參數(shù) | 說明 |
---|---|
Promise<InputDeviceData> | Promise對象,異步返回輸入設備信息。 |
示例:
- // 獲取輸入設備id為1的設備信息。
- inputDevice.getDevice(1).then((deviceData) => {
- console.log(`Device info: ${JSON.stringify(deviceData)}`);
- });
supportKeys(deviceId: number, keys: Array<KeyCode>, callback: AsyncCallback <Array<boolean>>): void
獲取輸入設備是否支持指定的鍵碼值,使用AsyncCallback異步方式返回結(jié)果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
deviceId | number | 是 | 輸入設備id,同一個物理設備反復插拔,設備id會發(fā)生變化。 |
keys | Array<KeyCode> | 是 | 需要查詢的鍵碼值,最多支持5個按鍵查詢。 |
callback | AsyncCallback<Array<boolean>> | 是 | 回調(diào)函數(shù),異步返回查詢結(jié)果。 |
示例:
- // 查詢id為1的輸入設備對于17、22和2055按鍵的支持情況。
- try {
- inputDevice.supportKeys(1, [17, 22, 2055], (error, supportResult) => {
- console.log(`Query result: ${JSON.stringify(supportResult)}`);
- });
- } catch (error) {
- console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
supportKeys(deviceId: number, keys: Array<KeyCode>): Promise<Array<boolean>>
獲取輸入設備是否支持指定的鍵碼值,使用Promise異步方式返回結(jié)果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
deviceId | number | 是 | 輸入設備id,同一個物理設備反復插拔,設備id會發(fā)生變化。 |
keys | Array<KeyCode> | 是 | 需要查詢的鍵碼值,最多支持5個按鍵查詢。 |
返回值:
參數(shù) | 說明 |
---|---|
Promise<Array<boolean>> | Promise對象,異步返回查詢結(jié)果。 |
示例:
- // 查詢id為1的輸入設備對于17、22和2055按鍵的支持情況。
- try {
- inputDevice.supportKeys(1, [17, 22, 2055]).then((supportResult) => {
- console.log(`Query result: ${JSON.stringify(supportResult)}`);
- });
- } catch (error) {
- console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
getKeyboardType(deviceId: number, callback: AsyncCallback<KeyboardType>): void
獲取輸入設備的鍵盤類型,使用AsyncCallback異步方式返回結(jié)果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
deviceId | number | 是 | 輸入設備的唯一標識,同一個物理設備反復插拔,設備id會發(fā)生變化。 |
callback | AsyncCallback<KeyboardType> | 是 | 回調(diào)函數(shù),異步返回查詢結(jié)果。 |
示例:
- // 查詢id為1的輸入設備的鍵盤類型。
- try {
- inputDevice.getKeyboardType(1, (error, type) => {
- if (error) {
- console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
- return;
- }
- console.log(`Keyboard type: ${JSON.stringify(type)}`);
- });
- } catch (error) {
- console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
getKeyboardType(deviceId: number): Promise<KeyboardType>
獲取輸入設備的鍵盤類型,使用AsyncCallback異步方式返回結(jié)果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
deviceId | number | 是 | 輸入設備的唯一標識,同一個物理設備反復插拔,設備id會發(fā)生變化。 |
返回值:
參數(shù) | 說明 |
---|---|
Promise<KeyboardType> | Promise對象,異步返回查詢結(jié)果。 |
示例:
- // 示例查詢設備id為1的設備鍵盤類型。
- try {
- inputDevice.getKeyboardType(1).then((type) => {
- console.log(`Keyboard type: ${JSON.stringify(type)}`);
- });
- } catch (error) {
- console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
輸入設備熱插拔的描述信息。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
type | 是 | 否 | 輸入設備插入或者移除。 | |
deviceId | number | 是 | 否 | 輸入設備的唯一標識,同一個物理設備反復插拔,設備id會發(fā)生變化。 |
輸入設備的描述信息。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
id | number | 是 | 否 | 輸入設備的唯一標識,同一個物理設備反復插拔,設備id會發(fā)生變化。 |
name | string | 是 | 否 | 輸入設備的名字。 |
sources | Array<SourceType> | 是 | 否 | 輸入設備支持的源類型。比如有的鍵盤上附帶觸摸板,則此設備有keyboard和touchpad兩種輸入源。 |
axisRanges | Array<AxisRange> | 是 | 否 | 輸入設備的軸信息。 |
bus9+ | number | 是 | 否 | 輸入設備的總線類型。 |
product9+ | number | 是 | 否 | 輸入設備的產(chǎn)品信息。 |
vendor9+ | number | 是 | 否 | 輸入設備的廠商信息。 |
version9+ | number | 是 | 否 | 輸入設備的版本信息。 |
phys9+ | string | 是 | 否 | 輸入設備的物理地址。 |
uniq9+ | string | 是 | 否 | 輸入設備的唯一標識。 |
輸入設備的軸類型。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
touchMajor | string | 是 | 否 | 表示touchMajor軸。 |
touchMinor | string | 是 | 否 | 表示touchMinor軸。 |
toolMinor | string | 是 | 否 | 表示toolMinor軸。 |
toolMajor | string | 是 | 否 | 表示toolMajor軸。 |
orientation | string | 是 | 否 | 表示orientation軸。 |
pressure | string | 是 | 否 | 表示pressure軸。 |
x | string | 是 | 否 | 表示x軸。 |
y | string | 是 | 否 | 表示y軸。 |
NULL | string | 是 | 否 | 無。 |
輸入設備的軸信息。
系統(tǒng)能力: SystemCapability.MultimodalInput.Input.InputDevice
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
source | 是 | 否 | 軸的輸入源類型。 | |
axis | 是 | 否 | 軸的類型。 | |
max | number | 是 | 否 | 軸的最大值。 |
min | number | 是 | 否 | 軸的最小值。 |
fuzz9+ | number | 是 | 否 | 軸的模糊值。 |
flat9+ | number | 是 | 否 | 軸的基準值。 |
resolution9+ | number | 是 | 否 | 軸的分辨率。 |
軸的輸入源類型。比如鼠標設備可上報x軸事件,則x軸的輸入源就是鼠標。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.InputDevice
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
keyboard | string | 是 | 否 | 表示輸入設備是鍵盤。 |
touchscreen | string | 是 | 否 | 表示輸入設備是觸摸屏。 |
mouse | string | 是 | 否 | 表示輸入設備是鼠標。 |
trackball | string | 是 | 否 | 表示輸入設備是軌跡球。 |
touchpad | string | 是 | 否 | 表示輸入設備是觸摸板。 |
joystick | string | 是 | 否 | 表示輸入設備是操縱桿。 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: