Method for remotely operating hardware function keys of Android terminal based on virtual keyboard equipment
By creating a virtual keyboard device on the Android terminal and using HTTP requests to convert them into hardware key operation logic, the problem of traditional terminal testing relying on manual operation is solved. This enables efficient automated terminal testing and remote control of custom keys, improving testing efficiency and accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-23
- Publication Date
- 2026-05-08
AI Technical Summary
Traditional terminal testing processes rely heavily on manual operation, which is time-consuming and manpower-intensive, and is easily affected by individual differences and fatigue of operators, making it difficult to guarantee the accuracy and reliability of test results.
By using a remote operation method based on a virtual keyboard device, HTTP requests are converted into hardware key operation logic to realize custom keys and remote triggering. This includes creating a virtual keyboard device on the Android terminal, loading a virtual device management module, an HTTP server module, and a key event handling module to achieve remote control of custom function keys.
It improves the efficiency of users or testers operating a large number of terminals, reduces the difficulty of using the equipment, simplifies application software development, and facilitates the parallel operation of multiple devices under test, thus reducing the workload of testers.
Smart Images

Figure CN121996442A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of automated testing, specifically a method for remotely operating the hardware function keys of an Android terminal based on a virtual keyboard device. Background Technology
[0002] With the continuous advancement of network terminal technology, their functions are becoming increasingly diversified. In order to simplify user operation when product functions are complex, manufacturers usually add hardware buttons to network terminal devices for quick function triggering.
[0003] Traditional terminal testing processes typically rely heavily on manual operation, which not only consumes a lot of time and human resources, but is also easily affected by human factors such as individual differences in operators and fatigue, making it difficult to fully guarantee the accuracy and reliability of test results.
[0004] Therefore, in order to effectively reduce the uncertainty introduced by manual button operation and significantly improve the overall testing efficiency, it is urgent to introduce a method that can automatically simulate hardware button actions to achieve the automation and standardization of the testing process.
[0005] In the Android system, hardware buttons on a terminal are typically mapped to one or more device nodes. Therefore, by creating a virtual keyboard device similar to the hardware buttons within the system and writing a custom key mapping table file, it is possible to flexibly simulate hardware function buttons beyond those on a regular keyboard.
[0006] Furthermore, by introducing HTTP services, network request events initiated by administrators or testers can drive the virtual keyboard to send key events, thus implementing a method for remotely operating hardware keys on network terminal devices. This separates software function testing from hardware key testing, helping relevant developers to accurately locate problems.
[0007] In addition, it facilitates testers to operate multiple devices under test in parallel, effectively reducing their workload. Summary of the Invention
[0008] To address the problems existing in the prior art, this invention provides a method for remotely operating the hardware function keys of an Android terminal based on a virtual keyboard device. By converting HTTP requests into hardware key operation logic, the functions of customizing keys and remotely triggering keys are realized. Users are not only spared the trouble of searching for hardware keys on the terminal, but also find it convenient to subsequently operate a large number of terminals in parallel and to achieve automated terminal testing.
[0009] The method for remotely operating the hardware function keys of an Android terminal based on a virtual keyboard device comprises the following steps:
[0010] Step 1: For Android device terminal A, the manufacturer pre-sets custom function keys and writes them into the corresponding mapping file;
[0011] Custom function keys are hardware keys included in non-standard keyboards, including mute keys, hands-free keys, or redial keys.
[0012] Mapping file: A text file containing the keyword "key", as well as the scan code and button name corresponding to the hardware button. Each line corresponds to one hardware button.
[0013] Step 2: Load the virtual device management module on terminal A, and create a virtual keyboard through the virtual device management module;
[0014] The specific process is as follows:
[0015] Step 201: Call the `open` statement to create a file descriptor `fd` for the virtual keyboard; the specific statement is as follows:
[0016] open(" / dev / uinput", O_WRONLY | O_NONBLOCK)
[0017] Step 202: Construct an ioctl statement to set the key event types and synchronization events supported by the virtual keyboard, and pass them to the file descriptor fd;
[0018] ioctl(fd, UI_SET_EVBIT, EV_KEY)
[0019] ioctl(fd, UI_SET_EVBIT, EV_SYN)
[0020] Step 203: Each custom function key calls the ioctl statement to set the key code corresponding to the custom function key on the virtual keyboard and pass it to the file descriptor fd;
[0021] The call statement is as follows: ioctl((fd, UI_SET_KEYBIT, KEY_SPEAKER);
[0022] KEY_SPEAKER is a custom constant, including the key code corresponding to the hands-free key or the key code corresponding to the mute key;
[0023] Step 204: Create a structure variable `usetup` of type `uinput_setup`, and write the properties of the virtual keyboard into it sequentially;
[0024] The attributes include the virtual keyboard's bus type, the virtual keyboard's manufacturer ID, the custom virtual keyboard ID, and the virtual keyboard name.
[0025] Step 205: Call the statement ioctl(fd, UI_DEV_SETUP, &usetup) to pass the structure variable usetup to the file descriptor fd;
[0026] Step 206: Call the statement ioctl(fd, UI_DEV_CREATE) to create a virtual keyboard.
[0027] Step 3: Load the HTTP server module on terminal A, and the user sends network request event B to the HTTP server module;
[0028] Network request event B contains a URL for the name of a custom function key; the URL contains the IP address of terminal A and the name of the custom key;
[0029] Step 4: The HTTP server module finds the key name and scan code corresponding to event B based on the mapping file, and packages the scan code into key event C and writes it to the virtual keyboard.
[0030] The HTTP server module listens on the port of device terminal A, parses the URL in request event B, and obtains the custom key name contained in the URL;
[0031] Then, the mapping file is read line by line to find the corresponding key name, the string of which is used as the key of the key-value pair, and the scan code after the key name is used as the value of the key-value pair; the key-value pair is then stored in a hash table.
[0032] Finally, create a key event C, take the key event type in the virtual keyboard as the type of key event C, and write it into the key value stored in the hash table; set the 01 state of the key being pressed / released and write it to the virtual keyboard.
[0033] Step 5: Load the key event handling module on terminal A, read the key events C written to the virtual keyboard, and the corresponding hardware key keyboard driver events D written to the virtual keyboard.
[0034] Step 6: The button event handling module transmits event C or D to the relevant application software via Android broadcast. After receiving the broadcast, the application software triggers the corresponding function according to the button type.
[0035] When the key event handling module receives a key event C or D, it encapsulates the scan code, key press state, and key long press state into a newly created Android broadcast message E, and carries the com.fv.aex.device.action.KEY_EVENT broadcast action. The message E is then distributed by the Android system to the application software listening for the above actions via Android broadcast.
[0036] The relevant application software is the software that registers the com.fv.aex.device.action.KEY_EVENT action listener with the Android system. After the Android system receives the message E containing the above action, it calls the onReceive(context: Context?, intent: Intent?) method in the application software, and then calls intent.getInt("keyCode") to get the type of the pressed key. Based on the key event type, it triggers the corresponding hardware button or virtual keyboard button, thereby triggering the corresponding function.
[0037] keyCode is the value of the scan code.
[0038] The advantages of this invention are:
[0039] 1. This invention is based on a device terminal with an Android system installed. It remotely controls the hardware buttons on the terminal via HTTP requests, realizing the conversion from HTTP requests to hardware button operations, improving the efficiency of users or testers operating a large number of terminals, and reducing the difficulty of using the device.
[0040] 2. In terms of implementation structure, the virtual button device and the real button device are similar in principle, and the subsequent processing flow of button events is the same. When the device malfunctions, it is helpful for personnel to distinguish whether the terminal has an application software problem or a hardware problem. The application software that receives custom buttons does not require additional permissions, which simplifies the development of application software on the device. Attached Figure Description
[0041] Figure 1 This is a flowchart of the method for remotely operating the hardware function keys of an Android terminal based on a virtual keyboard device according to the present invention;
[0042] Figure 2 This is a schematic diagram illustrating the communication principle between the various terminal modules, the hardware keyboard device, and the virtual keyboard device described in this invention. Detailed Implementation
[0043] To facilitate understanding and implementation of the present invention by those skilled in the art, the present invention will be further described in detail and in depth below with reference to the accompanying drawings.
[0044] This invention discloses a method for remotely operating hardware function keys of an Android terminal based on a virtual keyboard device. The user accesses a URL with key names using an Android device terminal that supports this method. The device terminal sends a key event to the key event handling module that is the same as when the hardware key is operated. That is, the hardware key on the device terminal is triggered by an HTTP request, and the HTTP request is converted into a custom hardware key operation.
[0045] like Figure 2 As shown, the Android device terminal sequentially loads a virtual device management module, an HTTP server module, and a key event handling module. After the device starts up, the Android system sends a startup completion message to the virtual device management module, which then creates a virtual keyboard. The HTTP server module receives a user's network request event, converts the custom key name in the event into a scan code according to a mapping file, and packages the scan code into a key event, writing it to the virtual keyboard. The Android system receives the key events from the virtual keyboard and distributes the events to the key event handling module. The key event handling module transmits each event to the relevant application software via Android broadcast. Upon receiving the broadcast, the application software triggers the corresponding function based on the key type.
[0046] like Figure 1 As shown, the specific steps are as follows:
[0047] Step 1: For Android device terminal A, the manufacturer pre-sets custom function keys and writes them into the corresponding mapping file;
[0048] Custom function keys are hardware keys that are pre-set by the manufacturer on the terminal and are not included in the standard keyboard, including mute keys, hands-free keys, or redial keys.
[0049] Mapping file: A text file containing the keyword "key", as well as the scan code and button name corresponding to the hardware button. Each line corresponds to one hardware button.
[0050] For example, key 508 SPEAKER indicates a hands-free key with scan code 508 and key name SPEAKER.
[0051] Step 2: Load the virtual device management module on terminal A, and create a virtual keyboard through the virtual device management module;
[0052] The virtual device management module creates and closes virtual keyboard devices using information such as the virtual keyboard's manufacturer ID, virtual keyboard ID, and the scan codes supported by the virtual keyboard.
[0053] The specific process is as follows:
[0054] Step 201: Call the open statement to create a write-only, non-blocking file descriptor fd for the virtual keyboard;
[0055] The statement is as follows:
[0056] open(" / dev / uinput", O_WRONLY | O_NONBLOCK)
[0057] `open` is the standard Linux system method for opening files.
[0058] / dev / uinput is a standard file; opening it creates a virtual input device.
[0059] O_WRONLY and O_NONBLOCK are standard system constants, representing write-only and non-blocking respectively.
[0060] Step 202: Construct an ioctl statement to set the key event types and synchronization events supported by the virtual keyboard, and pass them to the file descriptor fd;
[0061] ioctl(fd, UI_SET_EVBIT, EV_KEY)
[0062] ioctl(fd, UI_SET_EVBIT, EV_SYN)
[0063] octl is the standard method, meaning I / O control; UI_SET_EVBIT refers to setting supported events; EV_KEY and EV_SYN are the parameters required for the UI_SET_EVBIT event.
[0064] Step 203: Each custom function key calls the ioctl statement to set the key code corresponding to the custom function key on the virtual keyboard and pass it to the file descriptor fd;
[0065] The call statement is as follows: ioctl((fd, UI_SET_KEYBIT, KEY_SPEAKER);
[0066] UI_SET_KEYBIT refers to the supported key codes keyCode; KEY_SPEAKER is a custom constant, including key code 508 corresponding to the hands-free key or key code 509 corresponding to the mute key KEY_MUTE;
[0067] Step 204: Create a structure variable `usetup` of type `uinput_setup`, and write the properties of the virtual keyboard into it sequentially;
[0068] The attributes include: the virtual keyboard's bus type is BUS_VIRTUAL, written using the statement `usetup.id.bustype = BUS_VIRTUAL`; the virtual keyboard's manufacturer ID is 0x6666, written using the statement `usetup.id.vendor = 0x6666`; the custom virtual keyboard ID is 0x8888, written using the statement `usetup.id.product = 0x8888`; and the virtual keyboard name is virtual-fanvil, written using the statement `strncpy(usetup.name, "virtual-fanvil", UINPUT_MAX_NAME_SIZE - 1)`.
[0069] Step 205: Call the statement ioctl(fd, UI_DEV_SETUP, &usetup) to pass the structure variable usetup to the file descriptor fd;
[0070] Step 206: Call the statement ioctl(fd, UI_DEV_CREATE) to create a virtual keyboard.
[0071] Step 3: Load the HTTP server module on terminal A, and the user sends network request event B to the HTTP server module;
[0072] Network request event B contains a URL for the name of a custom function key; the URL contains the IP address of terminal A and the name of the custom key;
[0073] For example, http: / / 172.16.66.186 / cgi-bin / ConfigManApp.com?key=SPEAKER; 172.16.66.186 is the IP address of terminal A, / cgi-bin / ConfigManApp.com is the path of the module that can convert parameters into custom key operation logic, and key=SPEAKER specifies the name of the custom key.
[0074] Step 4: The HTTP server module finds the key name and scan code corresponding to event B based on the mapping file, and packages the scan code into key event C and writes it to the virtual keyboard.
[0075] The HTTP server module listens on port 80 of device terminal A, uses the HTTP service to parse the URL in request event B, and obtains the custom key name s contained in the URL;
[0076] Then, the mapping file is read line by line to find the corresponding key name s, and its string is used as the key of the key-value pair. The scan code following the key name s is used as the value of the key-value pair. The key-value pair is then stored in a hash table.
[0077] Finally, create a key event C, take the key event type in the virtual keyboard as the type of key event C, and write it into the key value stored in the hash table; set the 01 state of the key being pressed / released and write it to the virtual keyboard.
[0078] For example: The user accesses the URL: http: / / 172.16.66.188 / cgi-bin / ConfigManApp.com?key=SPEAKER; the HTTP server module calls opendir( / dev / input / ) to obtain all input device nodes, and retrieves the contents of the two files / sys / class / input / <device node name> / device / id / product and / sys / class / input / <device node name> / device / id / vendor for each of these device nodes; if a device with vendor is 0x6666 and product is 0x8888 is found, it is opened.
[0079] Convert SPEAKER to 508 according to the mapping file; create a key event C, set the type of key event C to EV_KEY, the key value of the key to 508, and the key press / release state, and then write it to the virtual keyboard.
[0080] Step 5: Load the key event handling module on terminal A, read the key events C written to the virtual keyboard, and the corresponding hardware key keyboard driver events D written to the virtual keyboard.
[0081] Call `keyboard->setCallback([this](int scanCode, bool isPressed, bool isLongPressed) { this->onKeyEvent(scanCode,isPressed, isLongPressed);})` on both the physical and virtual keyboard devices to pass the events sent by the physical and virtual keyboards to the key event handling module.
[0082] Step 6: The button event handling module transmits event C or D to the relevant application software via Android broadcast. After receiving the broadcast, the application software triggers the corresponding function according to the button type.
[0083] When the key event handling module receives a key event C or D, it encapsulates the scan code, key press state, and key long press state into a newly created Android broadcast message E, and carries the com.fv.aex.device.action.KEY_EVENT broadcast action. The message E is then distributed by the Android system to the application software listening for the above actions via Android broadcast.
[0084] The relevant application software is the software that registers the com.fv.aex.device.action.KEY_EVENT action listener with the Android system. After the Android system receives the message E containing the above action, it calls the onReceive(context: Context?, intent: Intent?) method in the application software, and then calls intent.getInt("keyCode") to get the type of the pressed key. Based on the key event type, it triggers the corresponding key on the hardware button or the virtual keyboard, thereby triggering the corresponding function.
[0085] keyCode is the value of the scan code.
[0086] Example:
[0087] In this embodiment, an event structure 1 of type input_event is created. gettimeofday(&event.time,NULL) sets the event time to the current timestamp, event.type = EV_KEY sets the type to a key event, event.code = keycode sets the scan code of the custom key, and event.value = press sets the pressed state of the custom key. Write(fd, &event, sizeof(event)) is called to write event structure 1 to the virtual device and obtains the return value ret. It is then determined whether the value of ret is less than the size of event structure 1 in bytes. If so, the HTTP server returns a 500 error message response.
[0088] Otherwise, reuse the aforementioned structure variable as the new event structure 2, set event.type = EV_SYN to set the type to synchronous event, event.code = SYN_REPORT to indicate the event boundary, and event.value = 0 to set the event default value; call write(fd, &event, sizeof(event)) to write event structure 2 to the virtual device and get the return value ret; check if the value of ret is less than the size of event structure 2 in bytes. If it is, the HTTP server returns a 500 error response; otherwise, it returns a 200 success response.
[0089] When the button event handling module receives the above event, it encapsulates the scan code, button press state, and button long press state into a newly created Android broadcast message, and distributes the message to the relevant application software via Android broadcast.
[0090] In the onEvent(const EventPtr &event) callback, create a Bundle variable of Android broadcast message data type, bundle.pub("keyCode", static_cast <int>(data.scanCode) sets the key code in the message data to the scan code, and bundle.pub("isPressed", static_cast) <bool>(data.isPressed) sets the short-press state of a key in the message data, and bundle.pub("isLongPressed", static_cast) <bool> (data.isLongPressed) sets the long press state of the key in the message data; Intent intent(Intent::ACTION_INPUT_KEY_EVENT, bundle) creates an intent and adds the message data Bundle variable to the intent; Broadcaster::getInstance().postIntent(intent) calls a utility class function to dispatch a broadcast message containing key event data.< / bool> < / bool> < / int>
Claims
1. A method for remotely operating hardware function keys of an Android terminal based on a virtual keyboard device, characterized in that, Includes the following steps: Step 1: For Android device terminal A, the manufacturer pre-sets custom function keys and writes them into the corresponding mapping file; Mapping file: A text file containing the keyword "key", as well as the scan code and button name corresponding to the hardware button. Each line corresponds to one hardware button. Step 2: Load the virtual device management module on terminal A, and create a virtual keyboard through the virtual device management module; The specific process is as follows: Step 201: Call the `open` statement to create a file descriptor `fd` for the virtual keyboard; the specific statement is as follows: open(" / dev / uinput", O_WRONLY | O_NONBLOCK) Step 202: Construct an ioctl statement to set the key event types and synchronization events supported by the virtual keyboard, and pass them to the file descriptor fd; ioctl(fd, UI_SET_EVBIT, EV_KEY) ioctl(fd, UI_SET_EVBIT, EV_SYN) Step 203: Each custom function key calls the ioctl statement to set the key code corresponding to the custom function key on the virtual keyboard and pass it to the file descriptor fd; The call statement is as follows: ioctl((fd, UI_SET_KEYBIT, KEY_SPEAKER); KEY_SPEAKER is a custom key code constant; Step 204: Create a structure variable `usetup` of type `uinput_setup`, and write the properties of the virtual keyboard into it sequentially; Step 205: Call the statement ioctl(fd, UI_DEV_SETUP, &usetup) to pass the structure variable usetup to the file descriptor fd; Step 206: Call the statement ioctl(fd, UI_DEV_CREATE) to create a virtual keyboard; Step 3: Load the HTTP server module on terminal A, and the user sends network request event B to the HTTP server module; Network request event B contains a URL with the name of a custom function key; The URL contains the IP address of terminal A and the name of the custom button; Step 4: The HTTP server module finds the key name and scan code corresponding to event B based on the mapping file, and packages the scan code into key event C and writes it to the virtual keyboard. The HTTP server module listens on the port of device terminal A, parses the URL in request event B, and obtains the custom key name contained in the URL; Then, the mapping file is read line by line to find the corresponding key name, the string of which is used as the key of the key-value pair, and the scan code after the key name is used as the value of the key-value pair; the key-value pair is then stored in a hash table. Finally, create a key event C, use the key event type from the virtual keyboard as the type of key event C, and write it into the key value stored in the hash table; set the 0 / 1 state of the key being pressed / released and write it to the virtual keyboard; Step 5: Load the key event handling module on terminal A, read the key event C written to the virtual keyboard, and the event D written by the corresponding hardware key keyboard driver of the virtual keyboard; Step 6: The button event handling module transmits event C or D to the relevant application software via Android broadcast. After receiving the broadcast, the application software triggers the corresponding function according to the button type.
2. The method as described in claim 1, characterized in that, In step one, the custom function keys are hardware keys included in a non-standard keyboard, including mute keys, hands-free keys, or redial keys.
3. The method as described in claim 1, characterized in that, In step 204, the attributes include the bus type of the virtual keyboard, the manufacturer ID of the virtual keyboard, the custom virtual keyboard ID, and the virtual keyboard name.
4. The method as described in claim 1, characterized in that, In step six, when the key event handling module receives key event C or D, it encapsulates the scan code, key press state, and key long press state into a newly created Android broadcast message E, and carries the com.fv.aex.device.action.KEY_EVENT broadcast action. The message E is then distributed by the Android system to the application software listening for the above actions via Android broadcast.
5. The method as described in claim 4, characterized in that, The application software is the software that registers the com.fv.aex.device.action.KEY_EVENT action listener with the Android system; After the Android system receives a message E containing the above actions, it calls the onReceive(context:Context?, intent: Intent?) method in the application software, and then calls intent.getInt("keyCode") to get the type of the pressed key. Based on the key event type, it triggers the corresponding hardware key or virtual keyboard key, thereby triggering the corresponding function. keyCode is the value of the scan code.