Input device management provides functions such as listening for device hot swap events and querying the keyboard type of a specified device. For example, as a user enters text, the input method determines whether to launch the virtual keyboard based on whether a physical keyboard is currently inserted. Your application can determine whether a physical keyboard is inserted by listening to device hot swap events.
The following table lists the common APIs for input device management. For details about the APIs, see [ohos.multimodalInput.inputDevice](../reference/apis/js-apis-inputdevice.md).
| inputDevice | function getDeviceList(callback: AsyncCallback\<Array\<number>>): void; | Obtains the list of input devices.|
| inputDevice | function getKeyboardType(deviceId: number, callback: AsyncCallback\<KeyboardType>): void; | Obtains the keyboard type of the input device.|
| inputDevice | function on(type: "change", listener: Callback\<DeviceListener>): void; | Enables listening for device hot swap events.|
| inputDevice | function off(type: "change", listener?: Callback\<DeviceListener>): void; | Disables listening for device hot swap events.|
## Virtual Keyboard Detection
When a user enters text, the input method determines whether to launch the virtual keyboard based on whether a physical keyboard is currently inserted. Your application can determine whether a physical keyboard is inserted by listening to device hot swap events.
## How to Develop
1. Call the **getDeviceList** API to obtain the list of connected input devices. Call the **getKeyboardType** API to traverse all connected devices to check whether a physical keyboard exists. If a physical keyboard exists, mark the physical keyboard as connected. This step ensures that your application detects all inserted input devices before listening for device hot swap events.
2. Call the **on** API to listen for device hot swap events. If a physical keyboard is inserted, mark the physical keyboard as connected. If a physical keyboard is removed, mark the physical keyboard as disconnected.
3. When a user enters text, check whether a physical keyboard is connected. If a physical keyboard is not connected, launch the virtual keyboard.
Mouse pointer management provides the functions such as displaying or hiding the mouse pointer as well as querying and setting the pointer style. For example, you can determine whether to display or hide the mouse pointer when a user watches a video in full screen, and can switch the mouse pointer to a color picker when a user attempts color pickup.
The following table lists the common APIs for mouse pointer management. For details about the APIs, see [ohos.multimodalInput.pointer](../reference/apis/js-apis-pointer.md).
| pointer | function isPointerVisible(callback: AsyncCallback\<boolean>): void; | Checks the visible status of the mouse pointer. |
| pointer | function setPointerVisible(visible: boolean, callback: AsyncCallback\<void>): void; | Sets the visible status of the mouse pointer. This setting takes effect for the mouse pointer globally.|
| pointer | function setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback\<void>): void; | Sets the mouse pointer style. This setting takes effect for the mouse pointer style of a specified window. |
| pointer | function getPointerStyle(windowId: number, callback: AsyncCallback\<PointerStyle>): void; | Obtains the mouse pointer style. |
## Hiding the Mouse Pointer
When watching a video in full-screen mode, a user can hide the mouse pointer for an improved user experience.
When designing a color picker, you can have the mouse pointer switched to the color picker style during color pickup and then switched to the default style on completion of color pickup. This setting takes effect for the pointer style of a specified window in the current application. A total of 39 pointer styles can be set. For details, see [Pointer Style](../reference/apis/js-apis-pointer.md#pointerstyle9).
### How to Develop
1. Enable the color pickup function.
2. Obtain the window ID.
3. Set the mouse pointer to the color picker style.
4. End color pickup.
5. Set the mouse pointer to the default style.
```js
importwindowfrom'@ohos.window';
// 1. Enable the color pickup function.
// 2. Obtain the window ID.
window.getTopWindow((error,windowClass)=>{
windowClass.getProperties((error,data)=>{
varwindowId=data.id;
if(windowId<0){
console.log(`Invalid windowId`);
return;
}
try{
// 3. Set the mouse pointer to the color picker style.
HiSysEvent provides event logging APIs for OpenHarmony to record important information of key processes during system running. Besides, it supports shielding of event logging by event domain, helping you to evaluate the impact of event logging.
### Working Principles
Before logging system events, you need to complete HiSysEvent logging configuration. For details, see [HiSysEvent Logging Configuration](subsys-dfx-hisysevent-logging-config.md).
Before logging system events, you need to configure HiSysEvent logging. For details, see [HiSysEvent Logging Configuration](subsys-dfx-hisysevent-logging-config.md).
## How to Develop
### Use Cases
Use HiSysEvent logging to flush logged event data to disks.
Use HiSysEvent logging to flush logged event data to the event file.
### Available APIs
#### C++ Event Logging APIs
#### C++ Event Logging API
HiSysEvent logging is implemented using the API provided by the **HiSysEvent** class. For details, see the API Reference.
HiSysEvent logging is implemented using the API provided by the **HiSysEvent** class. For details, see the [API Header Files](/base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include/).
> In OpenHarmony-3.2-Beta3, HiSysEvent logging is open for restricted use to avoid event storms. The **HiSysEvent::Write** API in Table 1 is replaced by the **HiSysEventWrite** API in Table 2. The **HiSysEvent::Write** API has been deprecated. Use the **HiSysEventWrite** API instead for HiSysEvent logging.
**Table 1** C++ event logging API (deprecated)
**Table 1**Description of the C++ event logging API (deprecated)
| template<typename... Types> <br>static int Write(const std::string &domain, const std::string &eventName, EventType type, Types... keyValues) | Flushes logged event data to the event file.|
| HiSysEventWrite(domain, eventName, type, ...) | Flushes logged event data to the event file.|
**Table 3** Description of EventType enums
| Event Type | Description |
| --------- | ----------- |
| FAULT | Fault event.|
| STATISTIC | Statistical event.|
| SECURITY | Security event.|
| BEHAVIOR | Behavior event.|
#### C Event Logging API
HiSysEvent logging is implemented using the API provided in the following table. For details, see the [API Header Files](/base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include/).
**Table 4** Description of the C event logging API
| b | bool | Event parameter value of the bool type. |
| i8 | int8_t | Event parameter value of the int8_t type. |
| ui8 | uint8_t | Event parameter value of the uint8_t type. |
| i16 | int16_t | Event parameter value of the int16_t type. |
| ui16 | uint16_t | Event parameter value of the uint16_t type.|
| i32 | int32_t | Event parameter value of the int32_t type. |
| ui32 | uint32_t | Event parameter value of the uint32_t type.|
| i64 | int64_t | Event parameter value of the int64_t type. |
| ui64 | uint64_t | Event parameter value of the uint64_t type.|
| f | float | Event parameter value of the float type. |
| d | double | Event parameter value of the double type. |
| s | char* | Event parameter value of the char* type. |
| array | void* | Event parameter value of the array type. |
#### Kernel Event Logging APIs
The following table describes the kernel event logging APIs.
Kernel event logging is implemented using the APIs provided in the following table. For details, see the [API Header File](/kernel/linux/linux-5.10/include/dfx/hiview_hisysevent.h).
**Table 4** Kernel event logging APIs
**Table 9** Description of kernel event logging APIs
| int hisysevent_put_integer(struct hiview_hisysevent *event, const char *key, long long value); | Adds event parameters of the integer type to a **hisysevent** object. |
| int hisysevent_put_string(struct hiview_hisysevent *event, const char *key, const char *value); | Adds event parameters of the string type to a **hisysevent** object.|
| int hisysevent_write(struct hiview_hisysevent *event); | Flushes **hisysevent** object data to disks. |
| int hisysevent_write(struct hiview_hisysevent *event); | Flushes **hisysevent** object data to the event file. |
**Table 5** Kernel event types
**Table 10** Description of hisysevent_type enums
| API | Description |
| --------- | ------------ |
| FAULT | Fault event|
| STATISTIC | Statistical event|
| SECURITY | Security event|
| BEHAVIOR | Behavior event|
| Event Type | Description |
| --------- | ----------- |
| FAULT | Fault event.|
| STATISTIC | Statistical event.|
| SECURITY | Security event.|
| BEHAVIOR | Behavior event.|
### How to Develop
#### C++ Event Logging
1.Call the event logging API wherever needed, with required event parameters passed to the API.
Call the event logging API wherever needed, with required event parameters passed to the API.
1. If you want to pass custom event parameters to the event logging API, create an event parameter object based on the event parameter type and add the object to the event parameter array.
```c
// Create an event parameter of the int32_t type.
HiSysEventParamparam1={
.name="KEY_INT32",
.t=HISYSEVENT_INT32,
.v={.i32=1},
.arraySize=0,
};
// Create an event parameter of the int32_t array type.
int32_tint32Arr[]={1,2,3};
HiSysEventParamparam2={
.name="KEY_INT32_ARR",
.t=HISYSEVENT_INT32_ARRAY,
.v={.array=int32Arr},
.arraySize=sizeof(int32Arr)/sizeof(int32Arr[0]),
};
// Add the event parameter object to the created event parameter array.
HiSysEventParamparams[]={param1,param2};
```
2. Call the event logging API wherever needed, with required event parameters passed to the API.
1. Create a **hisysevent** object based on the specified event domain, event name, and event type.
...
...
@@ -151,7 +260,7 @@ Assume that a service module needs to trigger event logging during application s
external_deps=["hisysevent_native:libhisysevent"]
```
2. In the application startup function **StartAbility()** of the service module, call the event logging API with the event parameters passed in.
2. In the application startup function **StartAbility()** of the service module, call the event logging API with event parameters passed in.
```c++
#include "hisysevent.h"
...
...
@@ -164,6 +273,37 @@ Assume that a service module needs to trigger event logging during application s
}
```
#### C Event Logging
Assume that a service module needs to trigger event logging during application startup to record the application startup event and application bundle name. The following is the complete sample code:
1. Add the HiSysEvent component dependency to the **BUILD.gn** file of the service module.
```c++
external_deps=["hisysevent_native:libhisysevent"]
```
2. In the application startup function **StartAbility()** of the service module, call the event logging API with event parameters passed in.
Assume that the kernel service module needs to trigger event logging during device startup to record the device startup event. The following is the complete sample code:
...
...
@@ -200,11 +340,10 @@ Assume that the kernel service module needs to trigger event logging during devi
}
```
#### Shielding of Event Logging by Event Domain
#### Shielding of Event Logging by Event Domain
- If you want to shield event logging for the **AAFWK** and **POWER** domains in a **.cpp** file, define the **DOMAIN_MASKS** macro before including the **hisysevent.h** header file to the **.cpp** file.
```c++
#define DOMAIN_MASKS "AAFWK|POWER"
#include "hisysevent.h"
...
...
@@ -212,14 +351,13 @@ Assume that the kernel service module needs to trigger event logging during devi
HiSysEventWrite(OHOS:HiviewDFX::HiSysEvent::Domain::AAFWK,"JS_ERROR",OHOS:HiviewDFX::HiSysEvent::EventType::FAULT,"MODULE","com.ohos.module");// HiSysEvent logging is not performed.
...// Other service logic
HiSysEventWrite(OHOS:HiviewDFX::HiSysEvent::Domain::POWER,"POWER_RUNNINGLOCK",OHOS:HiviewDFX::HiSysEvent::EventType::FAULT,"NAME","com.ohos.module");// HiSysEvent logging is not performed.
```
- If you want to shield event logging for the **AAFWK** and **POWER** domains of the entire service module, define the **DOMAIN_MASKS** macro as follows in the **BUILG.gn** file of the service module.