Shortcut key response processing method and device, electronic equipment and storage medium
By implementing the middle-layer shortcut key response processing for the target application in Wine, the problem that Windows-compatible applications cannot respond to shortcut keys globally is solved, and the function of the application being able to respond to shortcut keys normally in any state is realized, which improves the user's operation efficiency. Convenience.
Patent Information
- Application Number
- CN202411243558.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-05
- Publication Date
- 2025-01-21
AI Technical Summary
Windows-compatible applications running in Wine cannot respond to shortcut keys globally, and can only respond to shortcut keys when the window is focused, resulting in inconvenience in user operation.
By launching the target application in the middle layer, saving its registered shortcut keys, and listening to the raw key events it receives. Converts these events to standard key events and notifies the target app to respond to the shortcut key when it detects that the event is not a focus window event and the key code matches.
The global shortcut key response function that is compatible with Windows in WINE is realized. Even if the application is minimized or hidden, it can normally respond to the shortcut key to register, which improves the convenience of user operations.
Smart Images

Figure CN119336233A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a shortcut key response processing method, device, electronic device and storage medium. Background Art
[0002] Shortcut keys, also known as quick keys or hot keys, refer to the use of certain keys, key sequences or key combinations to complete an operation. Shortcut keys can be used to replace the mouse to do some work. For example, keyboard shortcuts can be used to open, close and navigate the Start menu, desktop, menus, dialog boxes and web pages.
[0003] Global response shortcut keys mean that as long as the application is in the startup state, no matter it is minimized, maximized, or hidden behind other application windows, it can normally respond to the shortcut keys registered by the application. For example, when the application "WeChat" is minimized, it can still respond to the shortcut keys of the "WeChat" screenshot function.
[0004] Wine (Wine Is Not an Emulator) is an open source compatibility layer that can run Windows-compatible applications on Unix-like operating systems (such as Linux, macOS, etc.). However, when running Windows-compatible applications in Wine, shortcut keys cannot be responded to globally. Only when the window focus is on the Windows-compatible application can the shortcut keys of the Windows-compatible application be responded to. Once the Windows-compatible application is minimized or in other non-focused states, the shortcut keys cannot be responded to, which brings great inconvenience to users.
[0005] Application Contents
[0006] In view of the above problems, an embodiment of the present application is proposed to provide a shortcut key response processing method that overcomes the above problems or at least partially solves the above problems. The function of global response shortcut keys of Windows compatible applications can be implemented in Wine, thereby improving the convenience of user operations in Wine.
[0007] Correspondingly, the embodiment of the present application also provides a shortcut key response processing device, an electronic device, and a storage medium to ensure the implementation and application of the above method.
[0008] In a first aspect, an embodiment of the present application discloses a shortcut key response processing method, which is applied to an intermediate layer, and the method includes:
[0009] Starting the target application in the middle layer and saving the shortcut keys registered by the target application;
[0010] Monitoring the original key events received by the target application; the original key events include original key press events or original key release events;
[0011] Convert the currently monitored target original key event into the first standard key event;
[0012] If it is determined that the target original key event is not a focus window event, and it is detected that the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application, the target application is notified to respond to the first standard key event.
[0013] In a second aspect, an embodiment of the present application discloses a shortcut key response processing device, which is applied to an intermediate layer, and the device includes:
[0014] A registration and saving module, used to start the target application in the middle layer and save the shortcut keys registered by the target application;
[0015] An event monitoring module, used to monitor the original key events received by the target application; the original key events include original key press events or original key release events;
[0016] An event conversion module, used for converting the currently monitored target original key event into a first standard key event;
[0017] The shortcut key response module is used to notify the target application to respond to the first standard key event if it is determined that the target original key event is not a focus window event and it is detected that the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application.
[0018] In the third aspect, an embodiment of the present application discloses an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of the shortcut key response processing method as described in any of the above.
[0019] In a fourth aspect, an embodiment of the present application discloses a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the shortcut key response processing method described in any one of the embodiments of the present application can be implemented.
[0020] The shortcut key response processing method, device, electronic device, and storage medium provided by the embodiments of the present application have the following advantages:
[0021] This application starts the target application in Wine and saves the shortcut keys registered by the target application. After the target application is started, all original key events received by the main process of the target application are monitored, that is, the event messages sent by the hardware device driver are directly captured. Before the X Server processes the original key events, the monitored target original key events are converted into first standard key events. If it is recognized that the target original key event is not a focus window event, and it is detected that the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application, the target application is notified to respond to the first standard key event to respond to the shortcut key. Therefore, this application can realize the function of Windows-compatible applications responding to shortcut keys globally in Wine. That is, for Windows-compatible applications started in Wine, regardless of whether the Windows-compatible application is minimized, maximized, or hidden behind other application windows, it can normally respond to the shortcut keys registered by the Windows-compatible application in Wine, which can improve the convenience of users' operations in Wine. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is a flowchart of the steps of an embodiment of a shortcut key response processing method of the present application;
[0023] Figure 2 This is a schematic diagram of the process framework of a shortcut key response processing method of the present application;
[0024] Figure 3 It is a structural block diagram of an embodiment of a shortcut key response processing device of the present application;
[0025] Figure 4 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0027] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally a class, and the number of objects is not limited. For example, the first object can be one or more. In addition, the term "and / or" in the specification and claims is used to describe the association relationship of associated objects, indicating that three kinds of relationships can exist, for example, A and / or B can be represented: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the front and back associated objects are a kind of "or" relationship. In the embodiment of the present application, the term "multiple" refers to two or more, and other quantifiers are similar.
[0028] Figure 1 A flowchart of an embodiment of a shortcut key response processing method of the present application is shown. The method is applied to the middle layer and may include the following steps:
[0029] Step 101: Start a target application in the middle layer and save the shortcut keys registered by the target application;
[0030] Step 102: monitor the original key events received by the target application; the original key events include original key press events or original key release events;
[0031] Step 103: convert the currently monitored target original key event into a first standard key event;
[0032] Step 104: If it is determined that the target original key event is not a focus window event, and it is detected that the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application, then notify the target application to respond to the first standard key event.
[0033] The shortcut key response processing method provided in the present application can be applied to a computer device based on a Linux operating system, wherein the Linux operating system is configured with an intermediate layer. The computer device may include but is not limited to any of the following: a server, a smart phone, a voice recorder, a tablet computer, an e-book reader, an MP3 (Moving Picture Experts Group Audio Layer III) player, an MP4 (Moving Picture Experts Group Audio Layer IV) player, a laptop computer, a car computer, a desktop computer, a set-top box, a smart TV, a wearable device, etc.
[0034] The embodiment of the present application does not limit the type of the Linux operating system. For example, the Linux operating system may include but is not limited to any one of Debian, Ubuntu, CentOS (Community Enterprise Operating System), UOS (Unicom Desktop Operating System), Kylin Operating System, and Fangde Operating System.
[0035] In the embodiment of the present application, the middle layer refers to a compatibility layer that can translate Windows applications into Linux applications, and the middle layer can realize running Windows compatible applications on Unix-like operating systems. The middle layer includes but is not limited to Wine and its downstream software.
[0036] In Linux operating systems with graphical interfaces, the graphical interface functions are provided by the X Window (also often called X11 or X) system, and the input method is also part of the graphical interface functions. The process running the application software does not read keyboard input directly, but only obtains input from the X server process through inter-process communication. The input of human-computer interaction is first read by the only X server process in the system, which performs preliminary processing uniformly and then distributes it to the appropriate process / thread.
[0037] The shortcut key response processing method provided in this application can realize the function of global response shortcut keys of Windows compatible applications in Wine. That is, for a Windows compatible application started in Wine, no matter the Windows compatible application is minimized, maximized, or hidden behind other application windows, it can normally respond to the shortcut keys registered by the Windows compatible application in Wine.
[0038] When the target application is started in Wine, the target application can register a usable shortcut key in Wine. The target application refers to a Windows compatible application that can be run in Wine.
[0039] Specifically, when the target application is started in Wine and initialized, the shortcut keys that can be used by the target application can be registered in Wine by calling the RegisterHotKey function. RegisterHotKey is a function in Windows API that can be used to register global shortcut keys. This function can bind the current application to the shortcut key registered with it, so that when the user presses the corresponding shortcut key, the system will automatically send the shortcut key message to the bound application, so that the application responds to the shortcut key.
[0040] The prototype of the RegisterHotKey function is as follows:
[0041] BOOL RegisterHotKey(HWND hWnd,int id,UINT fsModifiers,UINT vk)
[0042] The meanings of the RegisterHotKey function parameters are as follows:
[0043] hWnd: the window handle to which the shortcut belongs, usually set to NULL, indicating binding with the current application; id: hotkey ID, used to uniquely identify the registered shortcut; fsModifiers: the modifier key of the shortcut, which can use a combination of keys, such as Ctrl, Alt, Shift, etc.; vk: the virtual key code of the shortcut, such as VK_F1 for the F1 key, VK_LEFT for the left arrow key, etc. The function returns a BOOL value, indicating whether the shortcut is successfully registered.
[0044] When the target application calls the RegisterHotKey function to register a shortcut key, the parameters that need to be passed in mainly include the window handle, hotkey ID, hotkey combination key, etc. After the target application successfully registers a shortcut key in Wine, when the shortcut key is pressed, Wine will automatically send a hotkey message WM_HOTKEY carrying the hotkey ID of the shortcut key to the target application, so that the target application responds to the shortcut key.
[0045] This application saves the shortcut keys registered by the target application in Wine, including the key codes corresponding to the shortcut keys registered by the target application. After the target application is started, this application monitors all original key events received by the target application. The original key events refer to the original key press events and original key release events of all master devices. The master device refers to a device that can directly interact with the target application, such as a keyboard and a mouse.
[0046] Furthermore, the embodiment of the present application first determines whether the current system supports XInput Extension. X Input Extension is a module in X11 that allows applications to process complex input devices (such as multi-touch devices and other advanced input devices). For example, it is determined whether the current system supports XInput2.0. If not, it returns and does not execute the subsequent process; if it is supported, it is determined whether the current process is the main process of the target application. If so, the shortcut keys registered by the target application are saved, and the original key press events and original key release events of all main devices are monitored for the main process; if it is not the main process, no monitoring is performed.
[0047] The main process is the first process started in a multi-process application and is responsible for starting and managing other child processes. The main process is usually responsible for initializing the application environment, loading configurations, creating other child processes, and managing the entire application life cycle. The main process is the main process of a Windows-compatible application and is responsible for managing the entire Windows-compatible application life cycle.
[0048] Raw key events are keyboard events provided by XInput Extension that are not processed by X Server. Raw key events provide key data directly from input devices without keyboard mapping or other preprocessing. In other words, raw key events refer to message events sent by device drivers such as keyboards, which are not processed by X Server. Message events processed by X Server are standard key events.
[0049] Standard key events are keyboard events that the X Server processes and distributes to client applications. These events are pre-processed by the X Server, including keyboard mapping, keyboard status updates, and possible keyboard input method processing (such as the input method framework).
[0050] In a specific implementation, for a target application that has been started in Wine, if the window of the main process of the target application (referred to as the main window) is not the focus window, for example, the target application is in a minimized state, then when the user presses the shortcut key of the target application, the target application will not respond to the shortcut key. To solve this problem, after the target application is started, the embodiment of the present application monitors all original key events received by the main process of the target application, and before the target original key event is processed by the X Server, the target original key event is converted into a first standard key event, which can be regarded as a special standard key event, and the first standard key event is further processed. For example, when it is identified that the target original key event is a shortcut key registered by the target application, and it is determined that the main window of the target application is not the focus window, the first standard key event obtained after the target original key event is converted is sent down for processing to notify the target application to respond to the shortcut key corresponding to the target original key event. As a result, the target application can still respond to the corresponding shortcut key when it loses focus, and the function of Windows-compatible applications responding to shortcut keys globally can be implemented in Wine.
[0051] Furthermore, the notifying the target application to respond to the first standard key event may include: sending a hotkey message WM_HOTKEY to the target application, wherein the hotkey message carries the hotkey ID of the shortcut key. For example, assuming that the target application is a WeChat program, the shortcut keys registered by the WeChat program include shortcut keys for performing a screenshot operation, and the hotkey ID of the registered screenshot shortcut key is 1, then the hotkey message sent to the WeChat program may carry a hotkey ID value of 1, and after receiving the hotkey message, the WeChat program will respond to the hotkey message to perform the operation corresponding to the shortcut key with the hotkey ID of 1, i.e., perform a screenshot operation.
[0052] After starting the target application in Wine, the present application monitors all original key events received by the main process of the target application, that is, directly captures the event message sent by the hardware device driver, and converts the monitored target original key event into a first standard key event before the X Server processes the original key event. In addition, when it is recognized that the target original key event is not a focus window event, a shortcut key function can be called to process the first standard key event. If the shortcut key function detects that the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application, the target application can be notified to respond to the shortcut key corresponding to the first standard key event.
[0053] This application can realize the function of global response shortcut keys of Windows compatible applications in Wine. That is, for Windows compatible applications started in Wine, no matter the Windows compatible applications are minimized, maximized, or hidden behind other application windows, they can normally respond to the shortcut keys registered by the Windows compatible applications in Wine, thereby improving the convenience of users' operations in Wine.
[0054] In an optional embodiment of the present application, monitoring the original key events received by the target application in step 102 may include:
[0055] Step S11, traversing the event queue of the target application, the event queue including all events received by the target application;
[0056] Step S12: determine whether the target event is a standard event based on the event type of the target event currently traversed; if the target event is not a standard event, determine whether the extended event type of the target event is the target type; if the extended event type of the target event is the target type, determine that the target event is the original key event currently monitored; wherein the target type includes an original key press event type or an original key release event type.
[0057] In the specific implementation, the structure of the original key event is defined as follows:
[0058]
[0059] XIRawEvent is a structure used to process raw input events in X11. It provides low-level input data, such as raw mouse movement, keyboard keystrokes, etc., and is usually used to implement high-precision or customized input processing.
[0060] Furthermore, the embodiment of the present application may first call a first function (such as XISelectEvents) to set the events to be monitored. For example, the events to be monitored include original key press events and original key release events. Then, a second function (such as XCheckIfEvent) is called to traverse the event queue of the target application, search the event queue for the original key event to be monitored, and retrieve the found original key event.
[0061] Specifically, the event queue of the target application is traversed by the second function XCheckIfEvent, and each event is searched in the event queue in turn. For the target event currently found, firstly, whether the target event is a standard event is determined according to the event type of the target event. For example, the event type field in the structure of the target event can be obtained, such as the above-mentioned type field. If it is identified that the event type field indicates a generic event (GenericEvent) type, it means that the target event is not a standard key event, but a non-standard key event. Then, the extended event type field in the structure of the target event is further obtained, such as the above-mentioned evtype field, to determine whether the extended event type of the target event is a target type. The target type includes a raw key press event (XI_RawKeyPress) type or a raw key release event (XI_RawKeyPress) type. If it is identified that the extended event type indicated by the extended event type field of the target event is a target type, the target event is determined to be a raw key event, and the target event is taken out and converted into a first standard key event.
[0062] In a specific implementation, the original key event is processed by the X Server to obtain a standard key event that can be recognized by the system. The structure of the standard key event is defined as follows:
[0063]
[0064] XEvent is a standard key event structure obtained after the original key event in X11 is processed by X Server.
[0065] It should be noted that, for the sake of distinction, the present application refers to the standard key event obtained through the processing of the X Server as the second standard key event, and the standard key event obtained through the conversion of the present application as the first standard key event.
[0066] During the process of traversing the event queue of the target application, if it is identified that the currently traversed target event is a standard key event (ie, the second standard key event), since Wine will automatically process it, this application can ignore the target event and not process it.
[0067] Among them, XKeyEvent is a structure used to describe keyboard events in X11. This structure contains detailed information related to keyboard keys, such as the key code, the status of modifier keys, the window when the event occurs, etc. This structure is usually used to handle KeyPress (key press) events and KeyRelease (key release) events. XKeyEvent is defined as follows:
[0068]
[0069] In the embodiment of the present application, for the currently monitored target original key event, further judgment is required to determine the subsequent processing logic. Therefore, the present application converts the currently monitored target original key event into a first standard key event for subsequent judgment processing.
[0070] In an optional embodiment of the present application, the step 103 of converting the currently monitored target original key event into the first standard key event may include:
[0071] The message type of the target original key event is converted into the message type of the standard key event, and the key code in the target original key event is converted into the key code of the standard key event.
[0072] Among them, converting the message type of the target original key event into the message type of the standard key event may include: if the target original key event is a raw key press event (XI_RawKeyPress), filling the event type in the structure of the target original key event with the standard key press event (KeyPress) type, that is, assigning KeyPress to the type field in the XEvent structure; if the target original key event is a raw key release event (XI_RawKeyRelease), filling the event type in the structure of the target original key event with the standard key release event (KeyRelease) type, that is, assigning KeyRelease to the type field in the XEvent structure.
[0073] The step of converting the key code in the target original key event into the key code of the standard key event may include: assigning the value of the detail field in the target original key event structure to the key code field in the keyboard event structure. Exemplarily, the step of converting the key code in the target original key event into the key code of the standard key event may be as follows:
[0074] event.xkey.keycode=raw_event->detail;
[0075] Among them, event is the first standard key event obtained after conversion, xkey is the keyboard event structure in event, keycode is the key code field in xkey, raw_event is the target original key event structure, and detail is the field in the target original key event structure.
[0076] In an optional embodiment of the present application, the method may further include:
[0077] Step S21, acquiring all second standard key events within a preset time period starting from monitoring the target original key event;
[0078] Step S22: compare each second standard key event acquired within the preset time period with the first standard key event. If there are consistent events, determine that the target original key event is a focus window event; otherwise, determine that the target original key event is not a focus window event.
[0079] In a specific implementation, each original key event will be processed by X Server to become a standard key event (second standard key event) recognizable by the system. If the input focus is on the main window of the target application, if the shortcut key of the target application is pressed at this time, an original key event will be generated. The original key event will become a second standard key event after being processed by X Server. Since the input focus is on the main window of the target application, the second standard key event is a focus window event. Wine will automatically process the second standard key event and send a hotkey message WM_HOTKEY to the target application to make the target application respond to the shortcut key. Therefore, if the currently monitored target original key event is a focus window event, Wine will automatically process it. This application can ignore the target original key event and not process the target original key to avoid repeated processing that results in responding to the shortcut key twice.
[0080] For the currently monitored target original key event, this application converts it into the first standard key event before X Server processes it. Since Wine itself responds to the shortcut keys of the focus window and ignores the shortcut keys of the non-focus window, if the target original key event is a focus window event, it will also become a standard key event after being processed by X Server and continue to be processed later. If the target original key event is not a focus window event, it will be ignored by Wine. At this time, this application will continue to process the target original key event later so that the application can respond to the corresponding shortcut key.
[0081] Furthermore, by default, the target application's main window can only receive the second standard key event processed by the XServer when it has the focus. Therefore, if the target application's main window receives a second standard key event processed by the XServer within a preset time period (a shorter time period) after receiving an original key event, it means that the target application's main window has the input focus, that is, the target application's main window is the focus window.
[0082] Therefore, the present application can obtain all second standard key events within a preset time period starting from monitoring the target original key event; and compare each second standard key event obtained within the preset time period with the first standard key event. The preset time period can be set according to actual needs. The preset time period can be the length of time required for an original key event to become a second standard key event after being processed by the X Server. Exemplarily, the preset time period is 500ms. If there is a second standard key event in the second standard key events obtained within the preset time period that is consistent with the first standard key event, it means that the main window of the target application receives the second standard key event obtained by processing the original key event after the original key event is processed by the X Server within the preset time period after receiving the original key event, then it can be determined that the target original key event is a focus window event; otherwise, it is determined that the target original key event is not a focus window event. Among them, the main window refers to the main process window.
[0083] In an example, after monitoring the target original key event, the target original key event is converted into a first standard key event, and the start time is set. By calling the function XCheckIfEvent in the xlib library to loop and obtain all second standard key events received within 500ms, each obtained second standard key event is compared with the first standard key event to determine whether the target original key event is a focus window event.
[0084] In the related art, if the main window of the target application does not have the input focus, that is, the main window of the target application is not the focus window, the target application cannot receive the second standard key event and cannot respond to the shortcut key. The present application converts the monitored target original key event into the first standard key event, and when it is identified that the target original key event is not the focus window event, that is, the main window of the target application is not the focus window, the first standard key event is continued to be processed, and the processing flow is sent to the next step for further processing, so that the target application can respond to the corresponding shortcut key.
[0085] In an optional embodiment of the present application, the method may further include:
[0086] Step S31, obtaining a first identifier of a focus window, and obtaining a second identifier of a main window of the target application;
[0087] Step S32, determining whether the first identifier and the second identifier are consistent, if they are consistent, determining that the target original key event is a focus window event; otherwise, determining that the target original key event is not a focus window event.
[0088] The present application can determine whether the target original key event is a focus window event by two methods. The first method is to compare all second standard key events received within a preset time period with the first standard key events. If there are consistent events, it means that the target original key event is a focus window event, otherwise it means that the target original key event is not a focus window event.
[0089] The second method is to compare the first identifier of the window where the current input focus is located with the second identifier of the main window of the target application. If the two are consistent, it is determined that the target original key event is a focus window event; otherwise, it is determined that the target original key event is not a focus window event.
[0090] For example, the present application can obtain the first identifier of the window a where the current input focus is located through the function XGetInputFocus in the xlib library, and obtain the second identifier of the main window b of the target application through the function GetFocus in Wine. The first identifier of window a is compared with the second identifier of window b. If the first identifier of window a is consistent with the second identifier of window b, it means that window a is window b, that is, the input focus is on the main window b of the target application, so it is determined that the target original key event is a focus window event; otherwise, it is determined that the target original key event is not a focus window event.
[0091] In an optional embodiment of the present application, the method may further include:
[0092] Step S41, calling a key processing function to process the first standard key event, and determining whether the first standard key event is a character event through the key processing function;
[0093] Step S42: If it is determined that the first standard key event is a character event, calling an input method program to respond to the first standard key event.
[0094] In a specific implementation, a key event may be triggered by a user entering characters in an input box. To avoid mistakenly responding to a character input event as a shortcut key event, the present application converts the currently monitored target original key event into a first standard key event, and after determining that the target original key event is not a focus window event, calls a key processing function to process the first standard key event. The key processing function can determine whether the first standard key event is a character event, and determine the next processing logic based on the determination result.
[0095] For example, if it is determined that the first standard key event is a character event, the input method program is called to respond to the first standard key event; if it is determined that the first standard key event is not a character event, it is further detected whether the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application. If they are consistent, the target application is notified to respond to the first standard key event.
[0096] Exemplarily, the key processing function may be a function XmbLookupString in the xlib library. The function may be used to process keyboard input events, and convert received keyboard input events into strings or key symbols, and determine whether the received keyboard input events are character events by the return value of the function. For example, the function XmbLookupString is called with the first standard key event as a parameter. If the function returns successfully, it indicates that the first standard key event is a character event; if the function returns failed, it indicates that the first standard key event is not a character event, but a key event.
[0097] In an optional embodiment of the present application, the method may further include:
[0098] Step S51: if it is determined that the first standard key event is not a character event, a global shortcut key flag is set, and a shortcut key function is called to process the first standard key event;
[0099] Step S52: When the global shortcut key flag is detected, the shortcut key function detects whether the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application. If they are consistent, the target application is notified to respond to the first standard key event.
[0100] In the case where it is determined that the first standard key event is not a character event, the present application can determine that the first standard key event is a key event. At this time, a global shortcut key flag can be set, and a shortcut key function can be called to process the first standard key event. The global shortcut key flag can be used to process only shortcut key situations to avoid situations that are not shortcut keys, such as avoiding situations where letters are entered into an input box. Exemplarily, a global variable can be added to store the flag.
[0101] The shortcut key function first detects whether the global shortcut key flag exists, and if the global shortcut key flag exists, further detects whether the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application, and if they are consistent, notifies the target application to respond to the first standard key event. That is, a hot key message is sent to the target application to notify the target application to respond to the corresponding shortcut key.
[0102] Furthermore, when the shortcut key function does not detect the global shortcut key flag, it indicates that the standard key event is obtained after being processed by the X Server, and the first standard key event is ignored without processing, and the processing flow of the standard key event originally defaulted by Wine is entered.
[0103] Furthermore, the present application calls a key processing function to process the first standard key event, and if it is determined that the first standard key event is not a character event, it may further determine whether the first standard key event meets a preset condition. The preset condition is used to indicate that the first standard key event is obtained by conversion by the present application, rather than by processing by XServer.
[0104] In a specific implementation, the original key event will be processed by X Server to become a standard key event and enter the default processing flow of Wine. The purpose of this application is to process the first standard key event converted by this application. In order to avoid repeated processing of the standard key event (second standard key event) converted by X Server, this application continues to determine whether the first standard key event meets the preset conditions after determining that the first standard key event is not a character event. The first standard key event that meets the preset conditions is obtained by this application from the target original key event monitored, and the target original key event is not a focus window event, so this application continues to process. For example, for the monitored target original key event, it is converted into a first standard key event. If it is detected that the target original key event is not a focus window event, and the first standard key event is not a character event, and the first standard key event meets the preset conditions, the global shortcut key flag can be set, and the shortcut key function can be called to process the first standard key event, so that the target application can respond to the corresponding shortcut key.
[0105] The present application does not limit the method for determining whether the preset conditions are met. For example, if the message type of a first standard key event is identified as the message type of a standard key event, but the extended event type of the first standard key event is the original key event type, it can be determined that the first standard key event is obtained by the present application converting the monitored target original key event, rather than being processed by the XServer, and therefore it is determined that the first standard key event meets the preset conditions. If the message type of a first standard key event is identified as the message type of a standard key event, and the extended event type of the first standard key event is also the standard key event type, indicating that the first standard key event is processed by the X Server, it is determined that the first standard key event does not meet the preset conditions.
[0106] Reference Figure 2, shows a schematic diagram of the process framework of a shortcut key response processing method of the present application. Figure 2 As shown, the shortcut key response processing method of the present application may include the following steps:
[0107] Step 1: Register shortcut keys.
[0108] Start the target application in Wine and register the shortcut key of the target application in Wine.
[0109] Exemplarily, the function X11DRV_RegisterHotKey can be implemented, which first determines whether the current system supports XInput2.0. If not, it returns to exit the current process; if it is supported, it determines whether the current process is the main process. If so, it monitors the original key press events and original key release events of all main devices, and saves the shortcut keys registered by the target application; if it is not the main process, it does not monitor.
[0110] Step 2: Receive key events.
[0111] Determine whether the event received by the target application is the original key event to be monitored.
[0112] Exemplarily, first, for each event in the event queue of the target application, determine whether the event type is a standard event. If it is not a standard event, then continue to determine whether it is an original key press event or an original key release event. If it is an original key press event or an original key release event, then convert it to the first standard key event; if it is a standard event, then do not process it.
[0113] Step 3: Distribute key events.
[0114] By judging whether the original key pressed is a focus window event, it is decided whether to send the original key press event for further processing.
[0115] Exemplarily, if it is determined that the currently monitored target original key is a focus window event, the target original key event will not be processed, and the target original key event will enter the default processing flow in Wine. If it is determined that the currently monitored target original key is not a focus window event, the first standard key event converted from the target original key event is sent to the next step for further processing.
[0116] Step4: Key processing.
[0117] Receive the first standard key event sent in Step 3, and call the key event processing function to determine whether the first standard key event is a character event or a key event.
[0118] Exemplarily, the next operation is determined by judging whether the first standard key event input is a character event through the key event processing function. If the first standard key event is judged to be a character event, the input method program is called to respond to the first standard key event; if the first standard key event is judged not to be a character event but a key event, it is further judged whether the first standard key event meets the preset conditions. If the preset conditions are met, a global shortcut key flag is added to facilitate subsequent judgment and processing, and the shortcut key function is called to continue processing the first standard key event; if the preset conditions are not met, no processing is performed, and the default processing flow in Wine is entered.
[0119] Step 5: Press the button to respond.
[0120] The shortcut key function detects whether there is a global shortcut key flag. If so, it determines whether the key code corresponding to the first standard key event is consistent with the key code corresponding to the shortcut key registered by the target application. If they are consistent, a hot key message is sent to the target application to enable the target application to respond to the corresponding shortcut key.
[0121] Take the target application as WeChat program as an example. After starting the WeChat program in Wine, enter Step 1, and the WeChat program registers shortcut keys in Wine. Assume that the registered shortcut keys include a screenshot shortcut key, and the hotkey ID is 1. In Step 1, save the key code corresponding to the screenshot shortcut key registered by the WeChat program. Enter Step 2 to monitor all original key events received by the main process of the WeChat program. For example, when a target event is generated when a user operates a computer external device, Step 2 will determine whether the target event is an original key event. If it is an original key event, it will be converted into a first standard key event; if it is not an original key event, it will be ignored and not processed. Enter Step 3 to determine whether the target event is a focus window event. If it is a focus window event, it will be ignored and not processed; if it is not a focus window event, the first standard key event will be sent to Step 4 for further processing. Enter Step 4 to determine whether the received first standard key event is a character event. If it is a character event, the input method program will be called to respond to the first standard key event; if it is not a character event, the global shortcut key flag will be set, and the shortcut key function will be called to process the first standard key event. Go to Step 5 to check whether there is a global shortcut key flag. If the global shortcut key flag is detected, determine whether the key code in the first standard key event sent is consistent with the key code of the shortcut key saved in Step 1. If they are consistent, send a hot key message with a hot key ID of 1 to the WeChat program. The WeChat program responds to the hot key message and performs a screenshot operation. If they are inconsistent, ignore it. If the global shortcut key flag is not detected, ignore it.
[0122] In a specific implementation, if multiple Windows-compatible applications are started in Wine, since different Windows-compatible applications have their own independent operating environments, the present application can implement the function of a global response shortcut key for each Windows-compatible application.
[0123] For example, assuming that application 1 and application 2 are started in Wine, and both application 1 and application 2 are currently in a minimized state, the present application can start a process for monitoring all original key events received by application 1, and start another process for monitoring all original key events received by application 2, thereby realizing the function of global response shortcut keys of application 1 and application 2 at the same time.
[0124] It is understandable that in order to avoid conflicts between shortcut keys of different Windows-compatible applications, when multiple Windows-compatible applications are started, different shortcut keys should be set for different Windows-compatible applications. For example, if the screenshot shortcut key registered by application 1 is "Ctrl+Alt+A", the shortcut key registered by application 2 should avoid using "Ctrl+Alt+A".
[0125] In summary, the shortcut key response processing method provided by the present application starts the target application in Wine and saves the shortcut keys registered by the target application. After the target application is started, all original key events received by the main process of the target application are monitored, that is, the event message sent by the hardware device driver is directly captured. Before the X Server processes the original key event, the monitored target original key event is converted into a first standard key event. If the target original key event is not a focus window event, and the key code corresponding to the first standard key event is detected to be consistent with the key code of the shortcut key registered by the target application, the target application is notified to respond to the first standard key event to respond to the shortcut key. Therefore, the present application can realize the function of global response shortcut keys of Windows compatible applications in Wine. That is, for Windows compatible applications started in Wine, regardless of whether the Windows compatible application is minimized, maximized, or hidden behind other application windows, it can normally respond to the shortcut keys registered by the Windows compatible application in Wine, which can improve the convenience of user operation in Wine.
[0126] It should be noted that, for the method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the described order of actions, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.
[0127] Reference Figure 3 , shows a structural block diagram of an embodiment of a shortcut key response processing device of the present application, the device is applied to the middle layer, and the device may include:
[0128] A registration and saving module 301 is used to start the target application in the middle layer and save the shortcut keys registered by the target application;
[0129] An event monitoring module 302 is used to monitor the original key events received by the target application; the original key events include original key press events or original key release events;
[0130] An event conversion module 303 is used to convert the currently monitored target original key event into a first standard key event;
[0131] The shortcut key response module 304 is used to notify the target application to respond to the first standard key event if it is determined that the target original key event is not a focus window event and it is detected that the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application.
[0132] Optionally, the event monitoring module includes:
[0133] A traversal submodule, used for traversing the event queue of the target application, wherein the event queue includes all events received by the target application;
[0134] The judgment submodule is used to judge whether the target event is a standard event according to the event type of the target event currently traversed. If the target event is not a standard event, it is judged whether the extended event type of the target event is the target type. If the extended event type of the target event is the target type, it is determined that the target event is the original key event currently monitored; wherein the target type includes the original key press event type or the original key release event type.
[0135] Optionally, the event conversion module is specifically used to convert the message type of the target original key event into the message type of the standard key event, and convert the key code in the target original key event into the key code of the standard key event.
[0136] Optionally, the device also includes a first focus judgment module, which is used to obtain all second standard key events within a preset time period starting from monitoring the target original key event; compare each second standard key event obtained within the preset time period with the first standard key event, and if there are consistent events, determine that the target original key event is a focus window event; otherwise, determine that the target original key event is not a focus window event.
[0137] Optionally, the device also includes a second focus judgment module, which is used to obtain a first identifier of the focus window and a second identifier of the main window of the target application; determine whether the first identifier and the second identifier are consistent. If the two are consistent, determine that the target original key event is a focus window event; otherwise, determine that the target original key event is not a focus window event.
[0138] Optionally, the device further comprises:
[0139] A character event detection module, used for calling a key processing function to process the first standard key event, and judging whether the first standard key event is a character event through the key processing function;
[0140] The character event response module is used to call an input method program to respond to the first standard key event if it is determined that the first standard key event is a character event.
[0141] Optionally, the device further comprises:
[0142] A flag setting module, configured to set a global shortcut key flag bit if it is determined that the first standard key event is not a character event, and call a shortcut key function to process the first standard key event;
[0143] The flag detection module is used for the shortcut key function to detect whether the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application when the global shortcut key flag is detected. If they are consistent, the target application is notified to respond to the first standard key event.
[0144] The shortcut key response processing device provided by the present application starts the target application in Wine and saves the shortcut keys registered by the target application. After the target application is started, all original key events received by the main process of the target application are monitored, that is, the event message sent by the hardware device driver is directly captured. Before the X Server processes the original key event, the monitored target original key event is converted into a first standard key event. If the target original key event is not identified as a focus window event, and the key code corresponding to the first standard key event is detected to be consistent with the key code of the shortcut key registered by the target application, the target application is notified to respond to the first standard key event to respond to the shortcut key. Therefore, the present application can realize the function of Windows compatible application global response shortcut keys in Wine. That is, for Windows compatible applications started in Wine, regardless of whether the Windows compatible application is minimized, maximized, or hidden behind other application windows, it can normally respond to the shortcut keys registered by the Windows compatible application in Wine, which can improve the convenience of user operation in Wine.
[0145] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0146] Reference Figure 4 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 4 As shown, the electronic device includes: a processor, a memory, a communication interface and a communication bus, and the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of the shortcut key response processing method of the aforementioned embodiment.
[0147] An embodiment of the present application provides a non-temporary computer-readable storage medium. When the instructions in the storage medium are executed by a program or processor of a terminal, the terminal is enabled to execute the steps of the shortcut key response processing method of the aforementioned embodiment.
[0148] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0149] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0150] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0151] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a predictable manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0152] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0153] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0154] Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A shortcut key response processing method, characterized in that: Applied to the middle layer, the method comprises: Starting a target application in the middle layer and saving shortcut keys registered by the target application; Monitoring the original key events received by the target application; the original key events include original key press events or original key release events; Convert the currently monitored target original key event into the first standard key event; If it is determined that the target original key event is not a focus window event, and it is detected that the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application, the target application is notified to respond to the first standard key event.
2. The method according to claim 1, characterized in that The monitoring of the original key events received by the target application includes: Traversing an event queue of the target application, the event queue including all events received by the target application; According to the event type of the target event currently traversed, determine whether the target event is a standard event. If the target event is not a standard event, determine whether the extended event type of the target event is the target type. If the extended event type of the target event is the target type, determine that the target event is the original key event currently monitored; wherein the target type includes the original key press event type or the original key release event type.
3. The method according to claim 1, characterized in that The step of converting the currently monitored target original key event into the first standard key event includes: The message type of the target original key event is converted into the message type of the standard key event, and the key code in the target original key event is converted into the key code of the standard key event.
4. The method according to claim 1, characterized in that The method further comprises: Acquire all second standard key events within a preset time period starting from monitoring the target original key event; Each second standard key event acquired within the preset time period is compared with the first standard key event. If there are consistent events, it is determined that the target original key event is a focus window event; otherwise, it is determined that the target original key event is not a focus window event.
5. The method according to claim 1, characterized in that The method further comprises: Acquire a first identifier of a focus window, and acquire a second identifier of a main window of the target application; It is determined whether the first identifier and the second identifier are consistent. If they are consistent, it is determined that the target original key event is a focus window event; otherwise, it is determined that the target original key event is not a focus window event.
6. The method according to claim 1, characterized in that The method further comprises: Calling a key processing function to process the first standard key event, and determining whether the first standard key event is a character event through the key processing function; If it is determined that the first standard key event is a character event, an input method program is called to respond to the first standard key event.
7. The method according to claim 6, characterized in that The method further comprises: If it is determined that the first standard key event is not a character event, a global shortcut key flag is set, and a shortcut key function is called to process the first standard key event; When the global shortcut key flag is detected, the shortcut key function detects whether the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application. If they are consistent, the target application is notified to respond to the first standard key event.
8. A shortcut key response processing device, characterized in that: Applied to the middle layer, the device comprises: A registration and saving module, used to start the target application in the middle layer and save the shortcut keys registered by the target application; An event monitoring module, used to monitor the original key events received by the target application; the original key events include original key press events or original key release events; An event conversion module, used for converting the currently monitored target original key event into a first standard key event; The shortcut key response module is used to notify the target application to respond to the first standard key event if it is determined that the target original key event is not a focus window event and it is detected that the key code corresponding to the first standard key event is consistent with the key code of the shortcut key registered by the target application.
9. An electronic device, characterized in that: include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of the shortcut key response processing method as described in any one of claims 1 to 7.
10. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the shortcut key response processing method as described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Adaptive shortcut key shielding method under Linux operating system
CN119621292A
Method, system, medium and product for avoiding shortcut key conflict in operating system
CN121143906A