当前位置:网站首页>Detailed explanation of multi-mode input event distribution mechanism
Detailed explanation of multi-mode input event distribution mechanism
2022-07-05 00:47:00 【Openharmony developer community】
Detailed explanation of multi-mode input event distribution mechanism
One 、 Overview of multimode input
Multimode input service is designed to support developers to provide users with a variety of human-computer interaction methods , On the basis of continuous improvement and support for traditional input , Multimode input will also play OpenAtom OpenHarmony( hereinafter referred to as “OpenHarmony”) The distributed advantage of , Improve the cross device interaction experience , Facing new scenes 、 New businesses provide system level support .
Multimode input Input The components are OpenHarmony System level input event management framework ; Connect a variety of input devices to the South , Gather multiple input events ( Key 、 touch ), Through unification / After standardized treatment , Distribute to consumers ( system service 、 application ).
The docking of southbound input devices includes many types of input devices , Such as : A touch screen 、 mouse 、 keyboard 、 Touch Pad 、 The remote control .
Two 、 Input event and device status data flow introduction
First , Let's look at the key data flow under the multi-mode input architecture , It is convenient for users to have an in-depth understanding from initiating an interactive request , To the system 、 The whole process of application giving an interactive response .
As shown in the figure below , There are two types of key data flows :
● Input device status data flow :
The input device status data describes the status changes of the input device and its device attribute information , Include : Device insertion 、 Remove state 、 Unique identification of equipment 、 Equipment name 、 Input mode supported by the device .
Enter device status data , Through the kernel device driver, it is reported to the input device status management module of the multi-mode input server . In the input device management module, the global input device status is managed and maintained , At the same time, the device status will be encapsulated as a listening interface and provided to the upper business module to monitor the status of the system input peripherals .
● Interactive input event data flow :
Interactive input event data is used to describe the keyboard 、 mouse 、 Touch screen input events ; Keyboard events include : Key code 、 Key timestamp 、 Information such as the device to which the key belongs ; Mouse events include : mouse X/Y coordinate 、 Mouse button ( Such as : Mouse left | in | Right ) Events, etc. ; Touch events include : Time stamp 、 Touch the location X/Y Coordinates, etc .
The input event data is reported by the device driver to the input event receiving module to complete the forwarding of input events from kernel space to user space , Then the input event preprocessing module is given to complete the standardized processing of input events ( Key KeyCode Mapping standardization, etc ), Finally, the input event distribution module completes the event distribution with the system preset distribution mechanism and principles .
Refer to the following data flow diagram , We can clearly understand that after the user initiates an interactive request through the input device , Enter the whole process of event reporting and distribution .
chart 1 Input event and device status data flow diagram
notes : Data flow diagram arrow schematic description
Enter the event pre-processing instructions of the event distribution module :
The input event distribution process will first pass through the input event interception module , When an interceptor is registered , Entering the event will terminate and continue to report , The corresponding interceptor will intercept all input events . This event interception feature currently mainly supports barrier free mode .
When there is no interceptor registration , The input event will be reported to the input event listening module , System level applications ( Such as : System settings 、 desktop ) By listening to input events , Support system level features ( Such as : The status bar is hidden / Disappear, etc ).
The event monitoring module will not prevent the event from continuing to report ; Support event monitoring at the same time , Input events will continue to be reported .
Key events will be reported to the subscription key distribution module for processing , Distribute to the corresponding application for processing , The event distribution process ends .
Other touch screen events and mouse events will not go through the subscription key distribution module , It will continue to be reported to the application window for processing .
3、 ... and 、 Multimode input event distribution principle
1. mouse / Touch screen event distribution principles
mouse / Which target does the touch screen coordinate point to , The input event is distributed to the corresponding target .
mouse / Touch screen event distribution special scenario description :
If there is no button on the mouse to press , Which target is the current mouse pointing to , Mouse input events are distributed to coordinate locked targets .
If a button on the mouse is pressed , Take the target locked by the mouse coordinate when the first button is pressed as the distribution target , Until all the buttons are lifted .
Touch screen input , Press the locked target with the first finger as the input event distribution target , Until all fingers are raised .
2. Key event distribution principle
The key event distribution takes the focus in the current user visual interface as the distribution target , Which target is the focus of the current interface , Key events are distributed to the corresponding target .
Four 、OpenHarmony 3.1 Interface description added in version
In order to better support upper layer applications and system services, real-time detection and processing of input device hot plug status change events , stay OpenHarmony 3.1 The new version is open JS API Interface , It can support passing JS API Monitor the hot plug event of the device . At the same time, it provides the way to obtain the unique identification of the hot plug input device by registering the callback interface . Input device hot plug monitoring interface and inputDevice.getDevice The detailed information of the hot plug device can be obtained by interface coordination , Include : Enter device name 、 Input types supported by the device ( keyboard | Touch screen | mouse | Game handle ) etc. .
1. New interface description of multi-mode input subsystem
Input peripheral hot plug monitoring interface :function on(type: "change", listener: Callback<DeviceListener>): void; Input peripheral to cancel listening interface :function off(type: “change”, listener?: CallbackDeviceListener): void;
2. Add interface parameter description
【DeviceListener】
【ChangeType】
3. Input device hot plug interface application scenario
Soft keyboard adaptive display : In the text editing scenario , The input method monitors the hot plug operation of the physical keyboard input device , It can adaptively decide whether the soft keyboard is displayed . When there is a physical keyboard device , The soft keyboard does not need to be displayed , The user input operation is completed through the physical keyboard . When there is no physical keyboard , Input method pop-up soft keyboard , The user completes the input operation through the soft keyboard .
4. Example of hot plug interface of input device
After having a preliminary understanding of the mouse hot plug monitoring interface , Let's learn more about , How to use input device hot plug interface in actual development :
Import module first
import inputDevice from '@ohos.multimodalInput.inputDevice';
2) The input device hot plug event monitoring is realized through the monitoring interface :
// Input method in the soft keyboard display logic by subscribing to the status of the physical keyboard : Insert / Pull out // according to isPhysicalkeyboardExist The value of determines whether the soft keyboard pops up ...let isPhysicalkeyboardExist = false;inputDevice.on("change", (callback) => { console.log("type: " + callback.type + ", deviceId: " + callback.deviceId); inputDevice.getDevice(callback.deviceId, (ret) => { console.log("The keyboard type of the device is: " + ret); if (ret == keyboard.ALPHABETIC_KEYBOARD && callback.type == 'add') { // The hot plug device is keyboard isPhysicalkeyboardExist = true; } else if (ret == keyboard.ALPHABETIC_KEYBOARD && callback.type == 'remove') { isPhysicalkeyboardExist = false; } });});...
3) By canceling the listening interface, the input device hot plug event cancels listening :
listener: function(data) { console.log("type: " + data.type + ", deviceId: " + data.deviceId);}// Cancel alone listener Listening in .inputDevice.off("change", this.listener);// Cancel all listening inputDevice.off("change");// After canceling listening , The soft keyboard pops up by default
notes : Cancel hot plug event listening interface , Enter the reference listener Optional ; When entering the reference belt listener On behalf of canceling a specific listening callback . When entering the reference, do not bring listener, It means to cancel all listening callbacks .
Through the above introduction , I'm sure you're right OpenHarmony We have a comprehensive understanding of the input event processing and distribution mechanism of the multi-mode input subsystem . At the same time, we are also interested in OpenHarmony 3.1 The new version of the input device hot plug monitoring interface is introduced in detail , More about the multimode input subsystem for developers API Welcome to the interface Gitee Learn more about :
https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
I believe you have the above basic knowledge as a cushion in the subsequent development , In the subsequent development, it can be more flexible , Develop applications with better interactive experience . Looking forward to working with developers to build the ultimate user experience . Last , We look forward to working together to build , Can be found in OpenHarmony Community (https://gitee.com/openharmony) Discuss with each other .
边栏推荐
- SAP UI5 应用开发教程之一百零七 - SAP UI5 OverflowToolbar 容器控件介绍的试读版
- Identifiers and keywords
- lambda表达式
- What did I pay for it transfer to testing post from confusion to firmness?
- Les phénomènes de « salaire inversé » et de « remplacement des diplômés » indiquent que l'industrie des tests a...
- GDB common commands
- Safety learning week4
- Some basic functions of enterprise projects are developed, and important things are saved to online first a
- 分布式BASE理论
- Netcore3.1 JSON web token Middleware
猜你喜欢
企业公司项目开发好一部分基础功能,重要的事保存到线上第一a
The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
Sorting selection sorting
各大主流编程语言性能PK,结果出乎意料
Visual explanation of Newton iteration method
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
Two numbers replace each other
Complete knapsack problem (template)
There is a new Post-00 exam king in the testing department. I really can't do it in my old age. I have
随机推荐
GDB common commands
[circuit design] optocoupler use and circuit design summary
Daily practice (18): stack containing min function
Consolidated expression C case simple variable operation
Actual combat simulation │ JWT login authentication
全网最全正则实战指南,拿走不谢
多模输入事件分发机制详解
[Yocto RM]10 - Images
4. Scala writes HelloWorld in idea, in-depth analysis of accompanying objects, and association of source packages
npm install报错 强制安装
揭露测试外包公司,关于外包,你或许听到过这样的声音
Complete knapsack problem (template)
It's too convenient. You can complete the code release and approval by nailing it!
SAP UI5 应用的主-从-从(Master-Detail-Detail)布局模式的实现步骤
Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
Parsing of XML
How many triangles are there in the golden K-line diagram?
SAP UI5 应用开发教程之一百零七 - SAP UI5 OverflowToolbar 容器控件介绍的试读版
全栈开发提效神器——ApiFox(Postman + Swagger + Mock + JMeter)
Is it safe to open and register new bonds? Is there any risk? Is it reliable?