openharmony 鸿蒙 js-apis-pointer

2025-06-12 浏览 (1)

@ohos.multimodalInput.pointer (Mouse Pointer)

The pointer module provides APIs related to pointer attribute management, such as querying and setting pointer attributes.

NOTE

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

Modules to Import

import { pointer } from '@kit.InputKit';

pointer.setPointerVisible

setPointerVisible(visible: boolean, callback: AsyncCallback<void>): void

Sets the visible status of the mouse pointer. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
visiblebooleanYesWhether the mouse pointer is visible. The value true indicates that the mouse pointer is visible, and the value false indicates the opposite.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.
801Capability not supported.

Example

try {
  pointer.setPointerVisible(true, (error: Error) => {
    if (error) {
      console.error(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Set pointer visible success`);
  });
} catch (error) {
  console.error(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

pointer.setPointerVisible

setPointerVisible(visible: boolean): Promise<void>

Sets the visible status of the mouse pointer. This API uses a promise to return the result.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
visiblebooleanYesWhether the mouse pointer is visible. The value true indicates that the mouse pointer is visible, and the value false indicates the opposite.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.
801Capability not supported.

Example

try {
  pointer.setPointerVisible(false).then(() => {
    console.log(`Set pointer visible success`);
  });
} catch (error) {
  console.error(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

pointer.setPointerVisibleSync10+

setPointerVisibleSync(visible: boolean): void

Sets the visible status of the mouse pointer. This API returns the result synchronously.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
visiblebooleanYesWhether the mouse pointer is visible. The value true indicates that the mouse pointer is visible, and the value false indicates the opposite.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

try {
  pointer.setPointerVisibleSync(false);
  console.log(`Set pointer visible success`);
} catch (error) {
  console.error(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

pointer.isPointerVisible

isPointerVisible(callback: AsyncCallback<boolean>): void

Obtains the visible status of the mouse pointer. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<boolean>YesCallback used to return the result. The value true indicates that the mouse pointer is visible, and the value false indicates the opposite.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

try {
  pointer.isPointerVisible((error: Error, visible: boolean) => {
    if (error) {
      console.error(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`);
  });
} catch (error) {
  console.error(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

pointer.isPointerVisible

isPointerVisible(): Promise<boolean>

Obtains the visible status of the mouse pointer. This API uses a promise to return the result.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Return value

TypeDescription
Promise<boolean>Promise used to return the visible status of the mouse pointer. The value true indicates that the mouse pointer is visible, and the value false indicates the opposite.

Example

try {
  pointer.isPointerVisible().then((visible: boolean) => {
    console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`);
  });
} catch (error) {
  console.error(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

pointer.isPointerVisibleSync10+

isPointerVisibleSync(): boolean

Obtains the visible status of the mouse pointer. This API returns the result synchronously.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Return value

TypeDescription
booleanVisible status of the mouse pointer. The value true indicates that the mouse pointer is visible, and the value false indicates the opposite.

Example

try {
  let visible: boolean = pointer.isPointerVisibleSync();
  console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`);
} catch (error) {
  console.error(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

pointer.getPointerStyle

getPointerStyle(windowId: number, callback: AsyncCallback<PointerStyle>): void

Obtains the mouse pointer style. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
windowIdnumberYesWindow ID. The value is an integer greater than or equal to -1. The value -1 indicates the global window.
callbackAsyncCallback<PointerStyle>YesCallback used to return the mouse pointer style.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
  if (error.code) {
    console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
    return;
  }
  let windowId = win.getWindowProperties().id;
  if (windowId < 0) {
    console.log(`Invalid windowId`);
    return;
  }
  try {
    pointer.getPointerStyle(windowId, (error: Error, style: pointer.PointerStyle) => {
      console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
    });
  } catch (error) {
    console.error(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
  }
});

pointer.getPointerStyle

getPointerStyle(windowId: number): Promise<PointerStyle>

Obtains the mouse pointer style. This API uses a promise to return the result.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
windowIdnumberYesWindow ID.

Return value

TypeDescription
Promise<PointerStyle>Promise used to return the mouse pointer style.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
  if (error.code) {
    console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
    return;
  }
  let windowId = win.getWindowProperties().id;
  if (windowId < 0) {
    console.log(`Invalid windowId`);
    return;
  }
  try {
    pointer.getPointerStyle(windowId).then((style: pointer.PointerStyle) => {
      console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
    });
  } catch (error) {
    console.error(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
  }
});

pointer.getPointerStyleSync10+

getPointerStyleSync(windowId: number): PointerStyle

Obtains the mouse pointer style, such as the east arrow, west arrow, south arrow, and north arrow. This API returns the result synchronously.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
windowIdnumberYesWindow ID.
The default value is -1, indicating the global mouse pointer style.

Return value

TypeDescription
PointerStyleMouse pointer style.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { pointer } from '@kit.InputKit';

let windowId = -1;
try {
  let style: pointer.PointerStyle = pointer.getPointerStyleSync(windowId);
  console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
} catch (error) {
  console.error(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

pointer.setPointerStyle

setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback<void>): void

Sets the mouse pointer style. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
windowIdnumberYesWindow ID.
pointerStylePointerStyleYesPointer style.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
  if (error.code) {
    console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
    return;
  }
  let windowId = win.getWindowProperties().id;
  if (windowId < 0) {
    console.log(`Invalid windowId`);
    return;
  }
  try {
    pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => {
      console.log(`Set pointer style success`);
    });
  } catch (error) {
    console.error(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
  }
});

pointer.setPointerStyle

setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise<void>

Sets the mouse pointer style. This API uses a promise to return the result.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
windowIdnumberYesWindow ID.
pointerStylePointerStyleYesPointer style.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
  if (error.code) {
    console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
    return;
  }
  let windowId = win.getWindowProperties().id;
  if (windowId < 0) {
    console.log(`Invalid windowId`);
    return;
  }
  try {
    pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => {
      console.log(`Set pointer style success`);
    });
  } catch (error) {
    console.error(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
  }
});

pointer.setPointerStyleSync10+

setPointerStyleSync(windowId: number, pointerStyle: PointerStyle): void

Sets the mouse pointer style. This API returns the result synchronously.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
windowIdnumberYesWindow ID.
pointerStylePointerStyleYesPointer style.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
  if (error.code) {
    console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
    return;
  }
  let windowId = win.getWindowProperties().id;
  if (windowId < 0) {
    console.log(`Invalid windowId`);
    return;
  }
  try {
    pointer.setPointerStyleSync(windowId, pointer.PointerStyle.CROSS);
    console.log(`Set pointer style success`);
  } catch (error) {
    console.error(`getPointerSize failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
  }
});

PrimaryButton10+

Type of the primary mouse button.

System capability: SystemCapability.MultimodalInput.Input.Pointer

NameValueDescription
LEFT0Left button.
RIGHT1Right button.

RightClickType10+

Enumerates shortcut menu triggering modes.

System capability: SystemCapability.MultimodalInput.Input.Pointer

NameValueDescription
TOUCHPAD_RIGHT_BUTTON1Tapping the right-button area of the touchpad.
TOUCHPAD_LEFT_BUTTON2Tapping the left-button area of the touchpad.
TOUCHPAD_TWO_FINGER_TAP3Tapping or pressing the touchpad with two fingers.
TOUCHPAD_TWO_FINGER_TAP_OR_RIGHT_BUTTON20+4Tapping or pressing the touchpad with two fingers, or tapping the right-button area of the touchpad.
TOUCHPAD_TWO_FINGER_TAP_OR_LEFT_BUTTON20+5Tapping or pressing the touchpad with two fingers, or tapping the left-button area of the touchpad.

PointerStyle

Enumerates mouse pointer styles.

System capability: SystemCapability.MultimodalInput.Input.Pointer

NameValueDescriptionLegend
DEFAULT0DefaultDefault.png
EAST1East arrowEast.png
WEST2West arrowWest.png
SOUTH3South arrowSouth.png
NORTH4North arrowNorth.png
WEST_EAST5West-east arrowWest_East.png
NORTH_SOUTH6North-south arrowNorth_South.png
NORTH_EAST7North-east arrowNorth_East.png
NORTH_WEST8North-west arrowNorth_West.png
SOUTH_EAST9South-east arrowSouth_East.png
SOUTH_WEST10South-west arrowSouth_West.png
NORTH_EAST_SOUTH_WEST11North-east and south-west adjustmentNorth_East_South_West.png
NORTH_WEST_SOUTH_EAST12North-west and south-east adjustmentNorth_West_South_East.png
CROSS13Cross (accurate selection)Cross.png
CURSOR_COPY14CopyCopy.png
CURSOR_FORBID15ForbidForbid.png
COLOR_SUCKER16SuckerColorsucker.png
HAND_GRABBING17Grabbing handHand_Grabbing.png
HAND_OPEN18Opening handHand_Open.png
HAND_POINTING19Hand-shaped pointerHand_Poniting.png
HELP20HelpHelp.png
MOVE21MoveMove.png
RESIZE_LEFT_RIGHT22Left and right resizingResize_Left_Right.png
RESIZE_UP_DOWN23Up and down resizingResize_Up_Down.png
SCREENSHOT_CHOOSE24Screenshot crosshairScreenshot_Cross.png
SCREENSHOT_CURSOR25ScreenshotScreenshot_Cursor.png
TEXT_CURSOR26Text selectionText_Cursor.png
ZOOM_IN27Zoom inZoom_In.png
ZOOM_OUT28Zoom outZoom_Out.png
MIDDLE_BTN_EAST29Scrolling eastMID_Btn_East.png
MIDDLE_BTN_WEST30Scrolling westMID_Btn_West.png
MIDDLE_BTN_SOUTH31Scrolling southMID_Btn_South.png
MIDDLE_BTN_NORTH32Scrolling northMID_Btn_North.png
MIDDLE_BTN_NORTH_SOUTH33Scrolling north-southMID_Btn_North_South.png
MIDDLE_BTN_NORTH_EAST34Scrolling north-eastMID_Btn_North_East.png
MIDDLE_BTN_NORTH_WEST35Scrolling north-westMID_Btn_North_West.png
MIDDLE_BTN_SOUTH_EAST36Scrolling south-eastMID_Btn_South_East.png
MIDDLE_BTN_SOUTH_WEST37Scrolling south-westMID_Btn_South_West.png
MIDDLE_BTN_NORTH_SOUTH_WEST_EAST38Moving as a cone in four directionsMID_Btn_North_South_West_East.png
HORIZONTAL_TEXT_CURSOR10+39Horizontal text selectionHorizontal_Text_Cursor.png
CURSOR_CROSS10+40CrossCursor_Cross.png
CURSOR_CIRCLE10+41CircleCursor_Circle.png
LOADING10+42Animation loadingLoading.png
Atomic service API: This API can be used in atomic services since API version 12.
RUNNING10+43Animation running in the backgroundRunning.png
Atomic service API: This API can be used in atomic services since API version 12.
MIDDLE_BTN_EAST_WEST18+44Scrolling east-westMID_Btn_East_West.png

pointer.setCustomCursor11+

setCustomCursor(windowId: number, pixelMap: image.PixelMap, focusX?: number, focusY?: number): Promise<void>

Sets the custom cursor style. This API uses a promise to return the result.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
windowIdnumberYesWindow ID.
pixelMapimage.PixelMapYesPixel map resource.
focusXnumberNoFocus x of the custom cursor. The value is greater than or equal to 0. The default value is 0.
focusYnumberNoFocus y of the custom cursor. The value is greater than or equal to 0. The default value is 0.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { image } from '@kit.ImageKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

// app_icon is an example resource. Configure the resource file based on the actual requirements.
this.getUIContext()?.getHostContext()?.resourceManager.getMediaContent($r("app.media.app_icon")).then((svgFileData) => {
  const svgBuffer: ArrayBuffer = svgFileData.buffer.slice(0);
  let svgImagesource: image.ImageSource = image.createImageSource(svgBuffer);
  let svgDecodingOptions: image.DecodingOptions = {desiredSize: { width: 50, height:50 }};
  svgImagesource.createPixelMap(svgDecodingOptions).then((pixelMap) => {
    window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
      let windowId = win.getWindowProperties().id;
        try {
          pointer.setCustomCursor(windowId, pixelMap).then(() => {
            console.log(`setCustomCursor success`);
          });
        } catch (error) {
          console.error(`setCustomCursor failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
        }
      });
  });
});

CustomCursor15+

Pixel map resource.

System capability: SystemCapability.MultimodalInput.Input.Pointer

NameTypeReadableWritableDescription
pixelMapimage.PixelMapNoNoDefines a custom cursor. The minimum size is subject to the minimum limit of the image. The maximum size is 256 x 256 px.
focusXnumberNoYesHorizontal coordinate of the cursor focus. The coordinates are restricted by the size of the custom cursor. The minimum value is 0, and the maximum value is the maximum width of the image. The default value is 0 if the parameter is left empty.
focusYnumberNoYesVertical coordinate of the cursor focus. The coordinates are restricted by the size of the custom cursor. The minimum value is 0, and the maximum value is the maximum height of the image. The default value is 0 if the parameter is left empty.

CursorConfig15+

Defines the custom cursor configuration.

System capability: SystemCapability.MultimodalInput.Input.Pointer

NameTypeReadableWritableDescription
followSystembooleanNoNoWhether to adjust the cursor size based on system settings. The value true means to adjust the cursor size based on system settings, and the value false means to use the custom cursor size. The adjustment range is [size of the cursor image, 256 x 256].

pointer.setCustomCursor15+

setCustomCursor(windowId: number, cursor: CustomCursor, config: CursorConfig): Promise<void>

Sets the custom cursor style. This API uses a promise to return the result. The cursor may be switched back to the system style in the following cases: application window layout change, hot zone switching, page redirection, moving of the cursor out of the window and then back to the window, or moving of the cursor in different areas of the window. In this case, you need to reset the cursor style.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
windowIdnumberYesWindow ID.
cursorCustomCursorYesPixel map resource.
configCursorConfigYesCustom cursor configuration, which specifies whether to adjust the cursor size based on system settings. If followSystem in CursorConfig is set to true, the supported adjustment range is [size of the cursor image, 256 x 256].

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Input Device Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Abnormal windowId parameter passed in. 2. Abnormal pixelMap parameter passed in; 3. Abnormal focusX parameter passed in.4. Abnormal focusY parameter passed in.
26500001Invalid windowId.

Example

import { image } from '@kit.ImageKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

// app_icon is an example resource. Configure the resource file based on the actual requirements.
this.getUIContext()?.getHostContext()?.resourceManager.getMediaContent($r("app.media.app_icon")).then((svgFileData) => {
  const svgBuffer: ArrayBuffer = svgFileData.buffer.slice(0);
  let svgImagesource: image.ImageSource = image.createImageSource(svgBuffer);
  let svgDecodingOptions: image.DecodingOptions = {desiredSize: { width: 50, height:50 }};
  svgImagesource.createPixelMap(svgDecodingOptions).then((pixelMap) => {
    window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
      let windowId = win.getWindowProperties().id;
        try {
          pointer.setCustomCursor(windowId, {pixelMap: pixelMap, focusX: 25, focusY: 25}, {followSystem: false}).then(() => {
            console.log(`setCustomCursor success`);
          });
        } catch (error) {
          console.error(`setCustomCursor failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
        }
      });
  });
});

pointer.setCustomCursorSync11+

setCustomCursorSync(windowId: number, pixelMap: image.PixelMap, focusX?: number, focusY?: number): void

Sets a custom cursor. This API returns the result synchronously.

System capability: SystemCapability.MultimodalInput.Input.Pointer

Parameters

NameTypeMandatoryDescription
windowIdnumberYesWindow ID. The value must be an integer greater than 0.
pixelMapimage.PixelMapYesPixel map resource.
focusXnumberNoFocus x of the custom cursor. The value is greater than or equal to 0. The default value is 0.
focusYnumberNoFocus y of the custom cursor. The value is greater than or equal to 0. The default value is 0.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { image } from '@kit.ImageKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

// app_icon is an example resource. Configure the resource file based on the actual requirements.
const svgFileData = this.getUIContext()?.getHostContext()?.resourceManager.getMediaContent($r("app.media.app_icon")).then((svgFileData) => {
  const svgBuffer: ArrayBuffer = svgFileData.buffer.slice(0);
  let svgImagesource: image.ImageSource = image.createImageSource(svgBuffer);
  let svgDecodingOptions: image.DecodingOptions = {desiredSize: { width: 50, height:50 }};
  svgImagesource.createPixelMap(svgDecodingOptions).then((pixelMap) => {
    window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
      let windowId = win.getWindowProperties().id;
        try {
          pointer.setCustomCursorSync(windowId, pixelMap, 25, 25);
          console.log(`setCustomCursorSync success`);
        } catch (error) {
          console.error(`setCustomCursorSync failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
        }
    });
  });
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Input Kit

harmony 鸿蒙Input_DeviceListener

harmony 鸿蒙Input_InterceptorEventCallback

harmony 鸿蒙Input_AxisEvent

harmony 鸿蒙Input_DeviceInfo

harmony 鸿蒙Input_DeviceListener

harmony 鸿蒙Input_Hotkey

harmony 鸿蒙Input_InterceptorEventCallback

harmony 鸿蒙Input_InterceptorOptions

harmony 鸿蒙Input_KeyEvent

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