W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
鼠標指針管理模塊,用于查詢和設置鼠標指針相關屬性。
本模塊首批接口從API version 9開始支持。后續(xù)版本的新增接口,采用上角標單獨標記接口的起始版本。
setPointerVisible(visible: boolean, callback: AsyncCallback<void>): void
設置鼠標指針顯示或者隱藏,使用AsyncCallback異步方式返回結果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.Pointer
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
visible | boolean | 是 | 鼠標指針是否顯示。 |
callback | AsyncCallback<void> | 是 | 回調函數。 |
示例:
- try {
- pointer.setPointerVisible(true, (error) => {
- if (error) {
- console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- return;
- }
- console.log(`Set pointer visible success`);
- });
- } catch (error) {
- console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
setPointerVisible(visible: boolean): Promise<void>
設置鼠標指針顯示或者隱藏,使用Promise異步方式返回結果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.Pointer
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
visible | boolean | 是 | 鼠標指針是否顯示。 |
返回值:
參數 | 說明 |
---|---|
Promise<void> | Promise對象。 |
示例:
- try {
- pointer.setPointerVisible(false).then(() => {
- console.log(`Set pointer visible success`);
- });
- } catch (error) {
- console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
isPointerVisible(callback: AsyncCallback<boolean>): void
獲取鼠標指針顯示或隱藏狀態(tài),使用AsyncCallback異步方式返回結果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.Pointer
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回調函數,異步返回鼠標指針顯示或隱藏狀態(tài)。 |
示例:
- try {
- pointer.isPointerVisible((error, visible) => {
- if (error) {
- console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- return;
- }
- console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`);
- });
- } catch (error) {
- console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
isPointerVisible(): Promise<boolean>
獲取鼠標指針顯示或隱藏狀態(tài),使用Promise異步方式返回結果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.Pointer
返回值:
參數 | 說明 |
---|---|
Promise<boolean> | Promise對象,異步返回鼠標指針顯示或隱藏狀態(tài)。 |
示例:
- try {
- pointer.isPointerVisible().then((visible) => {
- console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`);
- });
- } catch (error) {
- console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
getPointerStyle(windowId: number, callback: AsyncCallback<PointerStyle>): void
獲取鼠標樣式類型,使用AsyncCallback異步方式返回結果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.Pointer
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
windowId | number | 是 | 窗口id。 |
callback | AsyncCallback<PointerStyle> | 是 | 回調函數,異步返回鼠標樣式類型。 |
示例:
- import window from '@ohos.window';
- window.getLastWindow(this.context, (error, win) => {
- 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, style) => {
- console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
- });
- } catch (error) {
- console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
- });
getPointerStyle(windowId: number): Promise<PointerStyle>
獲取鼠標樣式類型,使用Promise異步方式返回結果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.Pointer
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
windowId | number | 是 | 窗口id。 |
返回值:
參數 | 說明 |
---|---|
Promise<PointerStyle> | Promise實例,異步返回鼠標樣式類型。 |
示例:
- import window from '@ohos.window';
- window.getLastWindow(this.context, (error, win) => {
- 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) => {
- console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
- });
- } catch (error) {
- console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
- });
setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback<void>): void
設置鼠標樣式類型,使用AsyncCallback異步方式返回結果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.Pointer
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
windowId | number | 是 | 窗口id。 |
pointerStyle | 是 | 鼠標樣式。 | |
callback | AsyncCallback<void> | 是 | 回調函數。 |
示例:
- import window from '@ohos.window';
- window.getLastWindow(this.context, (error, win) => {
- 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.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
- });
setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise<void>
設置鼠標樣式類型,使用Promise異步方式返回結果。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.Pointer
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
windowId | number | 是 | 窗口id。 |
pointerStyle | 是 | 鼠標樣式。 | |
Promise<void> | void | 是 | Promise對象。 |
示例:
- import window from '@ohos.window';
- window.getLastWindow(this.context, (error, win) => {
- 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.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
- });
鼠標樣式類型。
系統(tǒng)能力:SystemCapability.MultimodalInput.Input.Pointer
名稱 | 值 | 說明 | 圖示 |
---|---|---|---|
DEFAULT | 0 | 默認 | |
EAST | 1 | 向東箭頭 | |
WEST | 2 | 向西箭頭 | |
SOUTH | 3 | 向南箭頭 | |
NORTH | 4 | 向北箭頭 | |
WEST_EAST | 5 | 向西東箭頭 | |
NORTH_SOUTH | 6 | 向北南箭頭 | |
NORTH_EAST | 7 | 向東北箭頭 | |
NORTH_WEST | 8 | 向西北箭頭 | |
SOUTH_EAST | 9 | 向東南箭頭 | |
SOUTH_WEST | 10 | 向西南箭頭 | |
NORTH_EAST_SOUTH_WEST | 11 | 東北西南調整 | |
NORTH_WEST_SOUTH_EAST | 12 | 西北東南調整 | |
CROSS | 13 | 準確選擇 | |
CURSOR_COPY | 14 | 拷貝 | |
CURSOR_FORBID | 15 | 不可用 | |
COLOR_SUCKER | 16 | 滴管 | |
HAND_GRABBING | 17 | 并攏的手 | |
HAND_OPEN | 18 | 張開的手 | |
HAND_POINTING | 19 | 手形指針 | |
HELP | 20 | 幫助選擇 | |
MOVE | 21 | 移動 | |
RESIZE_LEFT_RIGHT | 22 | 內部左右調整 | |
RESIZE_UP_DOWN | 23 | 內部上下調整 | |
SCREENSHOT_CHOOSE | 24 | 截圖十字準星 | |
SCREENSHOT_CURSOR | 25 | 截圖 | |
TEXT_CURSOR | 26 | 文本選擇 | |
ZOOM_IN | 27 | 放大 | |
ZOOM_OUT | 28 | 縮小 | |
MIDDLE_BTN_EAST | 29 | 向東滾動 | |
MIDDLE_BTN_WEST | 30 | 向西滾動 | |
MIDDLE_BTN_SOUTH | 31 | 向南滾動 | |
MIDDLE_BTN_NORTH | 32 | 向北滾動 | |
MIDDLE_BTN_NORTH_SOUTH | 33 | 向北南滾動 | |
MIDDLE_BTN_NORTH_EAST | 34 | 向東北滾動 | |
MIDDLE_BTN_NORTH_WEST | 35 | 向西北滾動 | |
MIDDLE_BTN_SOUTH_EAST | 36 | 向東南滾動 | |
MIDDLE_BTN_SOUTH_WEST | 37 | 向西南滾動 | |
MIDDLE_BTN_NORTH_SOUTH_WEST_EAST | 38 | 四向錐形移動 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯系方式:
更多建議: