harmony 鸿蒙@ohos.multimodalInput.inputEventClient (Device Injection)

2022-08-09 浏览 (1006)

@ohos.multimodalInput.inputEventClient (Device Injection)

The inputEventClient module provides the device injection capability.

NOTE

  • The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • The APIs provided by this module are system APIs.

Modules to Import

import inputEventClient from '@ohos.multimodalInput.inputEventClient';

inputEventClient.injectEvent

injectEvent({KeyEvent: KeyEvent}): void

Injects keys (including single keys and combination keys).

System capability: SystemCapability.MultimodalInput.Input.InputSimulator

Parameters

NameTypeMandatoryDescription
KeyEventKeyEventYesInformation about the key event to inject.

Example

try {
  let backKeyDown: inputEventClient.KeyEvent = {
    isPressed: true,
    keyCode: 2,
    keyDownDuration: 0,
    isIntercepted: false
  }
  inputEventClient.injectEvent({ KeyEvent: backKeyDown });

  let backKeyUp: inputEventClient.KeyEvent = {
    isPressed: false,
    keyCode: 2,
    keyDownDuration: 0,
    isIntercepted: false
  };
  inputEventClient.injectEvent({ KeyEvent: backKeyUp });
} catch (error) {
  console.log(`Failed to inject KeyEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

inputEventClient.injectMouseEvent11+

injectMouseEvent({mouseEvent: MouseEvent}): void;

Injects a mouse/touchpad event.

System capability: SystemCapability.MultimodalInput.Input.InputSimulator

Parameters

NameTypeMandatoryDescription
mouseEventMouseEventYesMouse/touchpad event to inject.

Example

try {
  let mouseButtonUp = {
      action: 2,
      screenX: 200,
      screenY: 620,
      button: 0,
      toolType: 1,
  }
  inputEventClient.injectMouseEvent({ mouseEvent: mouseButtonUp });

  let mouseButtonDown = {
      action: 3,
      screenX: 200,
      screenY: 620,
      button: 0,
      toolType: 1,
  };
  inputEventClient.injectMouseEvent({ mouseEvent: mouseButtonDown });
} catch (error) {
  console.log(`Failed to inject MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

inputEventClient.injectTouchEvent11+

injectTouchEvent({touchEvent: TouchEvent}): void;

Injects a touchscreen event.

System capability: SystemCapability.MultimodalInput.Input.InputSimulator

Parameters

NameTypeMandatoryDescription
touchEventTouchEventYesTouchscreen event to inject.

Example

try {
  let touchEventUp = {
      action: 1,
      sourceType: 0,
      screenX: 200,
      screenY: 620,
      pressedTime: 0,
  };
  inputEventClient.injectTouchEvent({ touchEvent: touchEventUp });

  let touchEventDown = {
      action: 3,
      sourceType: 0,
      screenX: 200,
      screenY: 620,
      pressedTime: 0,
  };
    inputEventClient.injectTouchEvent({ touchEvent: touchEventDown });
} catch (error) {
    console.log(`Failed to inject touchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

KeyEvent

Represents the key event to inject.

System capability: SystemCapability.MultimodalInput.Input.InputSimulator

NameTypeReadableWritableDescription
isPressedbooleanYesNoWhether the key is pressed.
The value true indicates that the key is pressed, and the value false indicates the opposite.
keyCodenumberYesNoKeycode value. Currently, only the KEYCODE_BACK key is supported.
keyDownDurationnumberYesNoDuration for pressing a key, in μs.
isInterceptedbooleanYesNoWhether the key event can be intercepted.
The value true indicates that the key event can be intercepted, and the value false indicates the opposite.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/fdb8192654f840fdb2a591616f10c92a