Computer sleep prevention method and device, computer equipment and storage medium
By monitoring and timing peripherals without input status, if the preset threshold is exceeded, virtual instructions are used to simulate key and mouse operations to prevent the computer from hibernating, solving the problems of keyboard damage and single functions in the prior art, realizing a low-cost and low-dependence computer Anti-sleep solution.
Patent Information
- Application Number
- CN202310657948.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-05
- Publication Date
- 2024-12-06
AI Technical Summary
The existing computer anti-sleep device prevents the computer from entering a dormant state by typing the keyboard, which easily damages the keyboard, especially the laptop keyboard, and has a single function.
By obtaining the peripheral operation state, including the no input state, timing and determining whether the preset sleep time threshold is exceeded. If it exceeds, the computer's underlying API will be called to execute virtual instructions to simulate the real key and mouse operation, preventing the computer from entering the sleep state.
Effectively prevents the computer from entering a dormant state, reduces manpower operations, avoids damage to physical equipment, has low dependence and low cost, and is suitable for a variety of application scenarios, including large-screen advertising display systems and public-used computer systems.
Smart Images

Figure CN119088458A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a computer anti-sleep method, device, computer equipment and storage medium. Background Art
[0002] A computer, commonly known as a computer, is an electronic computing machine used for high-speed calculations. It can perform numerical calculations, logical calculations, and has storage and memory functions. It is a modern intelligent electronic device that can run according to programs and automatically and quickly process massive amounts of data.
[0003] Computer hibernation means that the currently running data is saved in the hard disk, and the whole machine will completely stop powering. When in hibernation, the computer system will completely disconnect from the power supply and stop all its external functions until the user presses the power button again to wake up the computer system.
[0004] Since computer systems are often not in a busy state when in use, the computer will automatically go into standby mode. When you need to use the computer, you need to turn on the power again. However, when the computer is turned on and off repeatedly in a short period of time, it will accelerate the degradation of the hardware and reduce the life of the hardware. High voltage will be generated during startup and shutdown, which can easily damage the hardware. In addition, if the server computer does not cancel the system sleep function, when the computer system enters sleep mode, the functions provided by the server will be forcibly stopped, and systems that rely on functions on the server will experience errors such as inaccessible services.
[0005] In the existing computer anti-sleep device, the device uses the method of striking the keyboard to prevent the computer from entering the sleep state. The striking force is too strong and it is easy to damage the computer keyboard, especially the notebook keyboard, and the function is single. Summary of the invention
[0006] The purpose of the embodiments of the present invention is to propose a computer anti-sleep method, device, computer equipment and storage medium to solve the problem that in the existing computer anti-sleep device, the device uses the method of tapping the keyboard to prevent the computer from entering the sleep state, the tapping force is too strong and it is easy to damage the computer keyboard, especially the notebook keyboard, and the function is single.
[0007] In order to solve the above technical problems, the present invention provides a computer anti-sleep method, wherein the computer is provided with a peripheral device and adopts the following technical solution, including the following steps:
[0008] Acquire the peripheral operation state, where the peripheral operation state includes a no-input state;
[0009] Timing the no-input state to obtain a no-input state duration;
[0010] According to the no-input state duration, determining whether the no-input state duration is greater than a preset sleep time threshold;
[0011] If the duration of the no-input state is greater than a preset sleep time threshold, the computer bottom layer API is called to execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering a sleep state.
[0012] Preferably, the step of obtaining the peripheral operation state, wherein the peripheral operation state includes a no-input state, specifically comprises:
[0013] Start a thread, where the thread is used to monitor the operating status of the peripheral device;
[0014] If the peripheral device has no input, the no-input state of the peripheral device is recorded.
[0015] Preferably, the step of timing the no-input state to obtain the duration of the no-input state specifically includes:
[0016] Starting a first timer, wherein the first timer is used to record the duration of the no-input state;
[0017] The no-input state duration is updated and stored at a preset frequency.
[0018] Preferably, the step of judging whether the duration of the no-input state is greater than a preset sleep time threshold according to the duration of the no-input state specifically includes:
[0019] Comparing the no-input state duration with the preset sleep time threshold;
[0020] A result of comparing the no-input state duration with the preset sleep time threshold is obtained.
[0021] Preferably, if the duration of the no-input state is greater than a preset sleep time threshold, the computer underlying API is called to execute virtual instructions to simulate real keyboard and mouse operations, and the steps of preventing the computer from entering the sleep state specifically include:
[0022] If the duration of the no-input state is greater than a preset sleep time threshold, calling the keyboard and mouse movement API instruction SendInput;
[0023] The mouse button API instruction mouse_event is called to prompt the computer to trigger a keyboard and mouse operation interrupt.
[0024] Preferably, if the duration of the no-input state is greater than a preset sleep time threshold, the computer underlying API is called to execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering a sleep state, and the step further includes:
[0025] Starting a second timer, the second timer is used to record the time for which the virtual command simulates the real keyboard and mouse operation;
[0026] When the time of simulating the real keyboard and mouse operation is equal to the simulation operation threshold, the execution of the virtual instruction to simulate the real keyboard and mouse operation is stopped.
[0027] In order to solve the above technical problems, the present invention further provides a computer anti-sleep device, which adopts the following technical solution, including:
[0028] An acquisition module, used for acquiring the peripheral operation state, wherein the peripheral operation state includes a no-input state;
[0029] A timing module, used for timing the no-input state to obtain a duration of the no-input state;
[0030] A processing module, configured to determine whether the duration of the no-input state is greater than a preset sleep time threshold according to the duration of the no-input state;
[0031] The simulation module is used to call the computer bottom API and execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering the sleep state if the duration of the no-input state is greater than a preset sleep time threshold.
[0032] Preferably, the simulation module comprises:
[0033] A mouse movement simulation module, used for calling the keyboard and mouse movement API instruction SendInput if the duration of the no-input state is greater than a preset sleep time threshold;
[0034] The mouse button simulation module is used to call the mouse button API instruction mouse_event to prompt the computer to trigger a keyboard and mouse operation interrupt.
[0035] In order to solve the above technical problems, the present invention also provides a computer device, which adopts the technical solution described below, including a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the above-mentioned computer anti-sleep method when executing the computer-readable instructions.
[0036] In order to solve the above technical problems, the present invention also provides a computer-readable storage medium, which adopts the technical solution described below, and stores computer-readable instructions on the computer-readable storage medium. When the computer-readable instructions are executed by the processor, the steps of the above-mentioned computer anti-sleep method are implemented.
[0037] Compared with the prior art, the present invention mainly has the following beneficial effects: by first acquiring the peripheral operation state, the peripheral operation state includes the no-input state; then timing the no-input state to obtain the no-input state duration; then judging whether the no-input state duration is greater than a preset sleep time threshold according to the no-input state duration; if the no-input state duration is greater than the preset sleep time threshold, calling the computer's underlying API, executing virtual instructions to simulate real keyboard and mouse operations, and preventing the computer from entering a sleep state; being able to effectively prevent the computer from entering a sleep state, reducing manual operations, and avoiding the investment in physical equipment, and being able to effectively avoid the situation where the computer cannot be used due to sleep, and can be implemented without relying on external hardware devices, with low dependence; only simple programming is required to achieve, with low cost; both Windows XP and subsequent systems can be deployed and used, and deployment is convenient; and can be deployed in a variety of application scenarios, such as large-screen advertising display systems, computer systems and server systems for public use such as hotels or government affairs, and the like. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the scheme in the present invention, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0039] Figure 1 is an exemplary system architecture diagram in which the present invention can be applied;
[0040] Figure 2 is a flow chart of an embodiment of a computer anti-sleep method of the present invention;
[0041] Figure 3 It is a structural schematic diagram of an embodiment of a computer anti-sleep device of the present invention;
[0042] Figure 4 It is a schematic structural diagram of an embodiment of a computer device of the present invention. DETAILED DESCRIPTION
[0043] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present invention; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention; the terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present invention or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0044] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0045] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings.
[0046] like Figure 1 As shown, the system architecture 100 may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 is used to provide a medium for a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0047] The user can use the first terminal device 101, the second terminal device 102 or the third terminal device 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0048] The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0049] The server 105 may be a server that provides various services, for example, a background server that provides support for pages displayed on the first terminal device 101 , the second terminal device 102 , and the third terminal device 103 .
[0050] It should be noted that the computer anti-sleep method provided in the embodiment of the present invention is generally executed by a server / terminal device, and accordingly, the computer anti-sleep device is generally arranged in the server / terminal device.
[0051] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0052] Embodiment 1
[0053] Continue to refer Figure 2 , shows a flow chart of an embodiment of a computer anti-sleep method of the present invention. The computer anti-sleep method comprises the following steps:
[0054] Step S1, obtaining the peripheral operation state, where the peripheral operation state includes a no-input state.
[0055] In this embodiment, the computer anti-sleep method is executed on the electronic device (eg Figure 1 The server / terminal device shown in the figure can receive the computer anti-sleep request through a wired connection or a wireless connection. It should be noted that the above wireless connection method may include but is not limited to 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAXX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.
[0056] Computer peripherals are a general term for input, output devices, and external storage in a computer system. They play a role in transmitting, transferring, and storing data and information, and are an important part of a computer system. Computer peripherals refer to any device other than the host computer. Computer peripherals are attached or auxiliary devices connected to a computer. Computer peripherals can expand a computer system. Input devices in computer peripherals include keyboards, mice, pen input devices, scanners, digital cameras, digital video cameras, etc. Output devices in computer peripherals include monitors, printers, CD burners, etc. External storage in computer peripherals includes hard disk storage, mobile storage, optical storage, etc.
[0057] This embodiment uses a keyboard and a mouse to illustrate the computer anti-sleep method. The peripheral operation state includes an input state and a no-input state. When in the input state, it means that the computer system is operating normally. At this time, it cannot enter the sleep mode, which affects the normal operation of the computer. When the peripheral is in the no-input state, it means that the current computer has not received the input information of the peripheral and has not exchanged information with the peripheral.
[0058] In some optional implementations of this embodiment, step S1 may further include the following steps:
[0059] Step S11, start a thread, the thread is used to monitor the operating status of the peripheral device.
[0060] A thread is a basic unit of independent scheduling and dispatching. A thread can be a kernel thread scheduled by the operating system kernel. The main functions of threads are as follows: First, improve the efficiency and performance of the program: By using multithreading, different tasks in the program can be assigned to different threads for parallel execution, thereby improving the efficiency and performance of the program. For example, if a program needs to perform network requests and local calculations at the same time, the network requests and local calculations can be executed in different threads respectively, thereby improving the response speed and processing power of the program. Second, realize asynchronous programming: By using multithreading, asynchronous programming can be realized, that is, when executing a task, there is no need to wait for the task to be completed, but other tasks can be continued, thereby improving the program response speed and user experience. For example, if a program needs to read files and process images at the same time, file reading and image processing can be executed in different threads respectively, thereby improving the program response speed and user experience. Third, realize concurrency control: By using multithreading, concurrency control can be realized, that is, when multiple threads access shared resources at the same time, data consistency and correctness can be guaranteed through locking and other mechanisms. For example, if a program needs to read and write data and perform calculations at the same time, the data reading and writing and calculations can be executed in different threads respectively, and a locking mechanism can be used to ensure the consistency and correctness of the data.
[0061] In this embodiment, the operating status of the peripheral device is continuously monitored and the operating behavior of the peripheral device is tracked through the opened thread, so that corresponding anti-sleep measures can be taken according to the continuous operating behavior of the peripheral device.
[0062] Step S12: If there is no input from the peripheral device, the no-input state of the peripheral device is recorded.
[0063] During the thread execution, the system API instruction GetLastInputInfo is called to obtain the time of the last keyboard or mouse operation in the computer system.
[0064] BOOL GetLastInputInfo(PLASTINPUTINFO plii);
[0065] In winuser.h,
[0066] #if(_WIN32_WINNT>=Ox0500) typedef struct tagLASTINPUTINFO{UINTcbSize;
[0067] DWORD dwTime;
[0068] }LASTINPUTINFO,*PLASTINPUTINFO; WINUSERAPI
[0069] BOOL WINAPI GetLastInputInfo(OUT PLASTINPUTINFO plii);
[0070] #endif / *_WIN32_WINNT>=Ox0500* /
[0071] This function can detect the movement of the mouse or keyboard in the system. The result dwTime can be compared with the result of the GetTickCount() function to get the time of user inactivity.
[0072] You can also use the kbhit function to check whether there is keyboard input. If so, it returns a non-zero value, otherwise it returns 0. For example, include the header file: include<conio.h> :
[0073] #include<conio.h>
[0074] int main(void){
[0075] cprintf("Press any key to continue:");
[0076] while(!kbhitO);
[0077] cprintf("\r\nA key was pressed...\r\n");
[0078] return o;
[0079] }
[0080] Step S2, timing the no-input state to obtain the no-input state duration.
[0081] In this embodiment, step S2 may further include the following steps:
[0082] Step S21: Start a first timer, where the first timer is used to record the duration of a no-input state.
[0083] A timer is a special type of clock that measures specific time intervals. The first timer records the duration of the no-input state.
[0084] Step S22: Refresh and store the duration of the no-input state at a preset frequency.
[0085] The preset frequency can be set according to actual needs, for example, it can be refreshed and stored once every 30 seconds, or once every 1 minute.
[0086] Step S3, judging whether the duration of the no-input state is greater than a preset sleep time threshold according to the duration of the no-input state.
[0087] In order to prevent the computer from entering a dormant state, a preset dormancy time threshold can be set according to actual needs. For example, according to the nature of the current computer work, such as whether it is used as a stand-alone machine, the preset dormancy time threshold can be 3 minutes or 5 minutes; for example, whether it is used as a server, the preset dormancy time threshold can be 10 minutes.
[0088] In this embodiment, step S3 may further include the following steps:
[0089] Step S31: compare the duration of the no-input state with a preset sleep time threshold.
[0090] The duration of the no-input state recorded by the first timer is compared with the preset sleep time threshold to compare the sizes.
[0091] Step S32: Obtain the result of comparing the duration of the no-input state with a preset sleep time threshold.
[0092] After comparison, there may be three results: the duration of no input state is greater than the preset sleep time threshold, the duration of no input state is equal to the preset sleep time threshold, and the duration of no input state is less than the preset sleep time threshold, and the comparison result is obtained.
[0093] Step S4, if the duration of the no-input state is greater than a preset sleep time threshold, the computer's underlying API is called to execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering a sleep state.
[0094] In this embodiment, step S4 may further include the steps of:
[0095] Step S41: If the duration of the no-input state is greater than a preset sleep time threshold, call the keyboard and mouse movement API instruction SendInput.
[0096] Once the duration of the no-input state is greater than the preset sleep time threshold, the mouse and keyboard movement API instruction SendInput is called to simulate the movement of the mouse and keyboard to prevent the computer from entering sleep mode.
[0097] SendInput function prototype:
[0098] UINT SendInput(
[0099] [in]UINT cInputs,
[0100] [in]LPINPUT pInputs,
[0101] [in]int cbSize).
[0102] The parameter clnputs, of type UINT (32-bit unsigned integer), is the number of arrays of the second parameter pInputs of the function SendInput(), which can be obtained using the ARRAYSIZE() method. The parameter plnputs, of type LPINPUT, is the INPUT structure pointer Q. When the object is instantiated, each object represents a simulated operation. The parameter cbSize, of type int, is the size of the input structure (in bytes), which can be obtained using the sizeof() method. The return value type is UINT. The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input has been blocked by another thread. To obtain extended error information, you can call the GetLastError function.
[0103] Step S42: calling the mouse button API instruction mouse_event to prompt the computer to trigger a keyboard and mouse operation interrupt.
[0104] Use the API function mouse_event to simulate mouse events. First add the following statement to the program:
[0105] Private Declare Sub mouse_event Lib"user32"(ByValdwFE1ags as Long,ByVal dx As Long,ByValdy As Long,ByVaLcButtons As Long,ByVa1dwExtraInfo AsLong);
[0106] The meaning of each parameter is:
[0107] dwF1ags Long, one of the flags in the following table or their combination;
[0108] dx, dy Long, specifies the absolute position or relative position in the x, y direction according to the MOUSEEVENTF_ABSOLUTE flag cButtons Long, not used;
[0109] dwExtraInfo Long, dwFlags constant meaning is not used;
[0110] MOUSEEVENTF_MOVE&H1, move the mouse;
[0111] MOUSEEVENTF_LEFTDOWN&H2, simulates the left mouse button being pressed;
[0112] MOUSEEVENTF__LEFTUP&H4, simulates the left mouse button being raised;
[0113] MOUSEEVENTF_RIGHTDOWN&H8, simulates the right button of the mouse being pressed;
[0114] MOUSEEVENTF_RIGHTUP&H10, simulates the right button of the mouse being lifted;
[0115] MOUSEEVENTF_MIDDLEDOWN&H20, simulates the middle mouse button being pressed;
[0116] MOUSEEVENTF_MIDDLEUP&H40, simulates the middle mouse button being lifted;
[0117] MOUSEEVENTF_ABSOLUTE&H8000, indicates whether to use absolute coordinates.
[0118] For example, the combination of the left mouse button press and release events is a click simulation example:
[0119] mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0.
[0120] Example of simulating a right-click event:
[0121] mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP,0, 0, 0, 0.
[0122] Two consecutive left-button clicks of the mouse constitute a double-click event. Example:
[0123] mouse_event MOUSEEVENTF_LEFTDOWN Or KOUSEEVENTF_LEFTUP, 0, 0, 0, 0
[0124] moue_event MOUSBEVBATF_LEETDOHYOr MOUSBVENT7_J1EFTUP,0,0,0,0.
[0125] As shown above, if you want to use a combination of two dwF1ags constants, you can connect them with Or. In this example, the dx and dy parameters are set to 0, which means that the position of each simulated event is the current position of the mouse. When the MOUSEVENTF_ABSOLUTE flag is not used, dx and dy are relative to the current position of the mouse. If it is set to use absolute coordinates, dx and dy are relative to the screen.
[0126] Then put these statements in the Timer event of the Timer control, and you can simulate mouse events at certain intervals.
[0127] For example:
[0128] CPointpt;
[0129] GetCursorPos(&pt); / / Get the current position of the mouse on the screen
[0130] SetCursorPos(100,200); / / Move to a certain point coordinate
[0131] ImOuse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0); / / right click
[0132] IIOuse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0); / / Release the right button
[0133] Imouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); / / Left click
[0134] mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); l / / Release the left button
[0135] Use the API function mouse_event to simulate mouse events, such as left-click, double-click, and right-click.
[0136] In some optional implementations of this embodiment, after step S4, the electronic device may further perform the following steps:
[0137] Step S5, start a second timer, the second timer is used to record the time of virtual instructions simulating real keyboard and mouse operations.
[0138] In order to prevent the simulated keyboard and mouse from operating continuously when there is no input from the peripheral device, which consumes power, it is preferred to perform simulation intermittently to save power consumption. Then, a second timer is started to record the time of virtual instructions simulating real keyboard and mouse operations.
[0139] Step S6: When the time for simulating the real keyboard and mouse operation is equal to the simulation operation threshold, the execution of the virtual instruction to simulate the real keyboard and mouse operation is stopped.
[0140] The simulation operation threshold can be set according to the actual situation. For example, when the current computer is used as a personal computer, the simulation operation threshold can be set to 3 minutes or 5 minutes; when the current computer is used as a server, the simulation operation threshold can be set to 10 minutes. In other words, when the simulation mouse and keyboard operation time reaches the simulation operation threshold, the simulation is stopped and the peripheral device continues to maintain a no-input state. When the no-input state reaches the preset sleep time threshold, the computer anti-sleep method of the present invention is executed to prevent the computer from entering a sleep state. This can be repeated in a cycle, which not only saves energy consumption, but also prevents the computer from entering a sleep state.
[0141] The present invention can be deployed in a variety of application scenarios:
[0142] First, the large-screen advertising display system. When the target computer system triggers hibernation, the target computer system will shut down or the screen will turn black, and the advertising video or picture will not be displayed normally. When using this software, this situation can be avoided.
[0143] Second, computer systems used for public use, such as hotel or government systems, often require someone to restart the computer and enter a password when the computer system is in hibernation. By using this software, complaints caused by the computer system being unable to provide services due to hibernation can be effectively avoided.
[0144] Third, the server system can prevent the problem that the server stops providing services to the outside world after the computer system goes into sleep mode.
[0145] The beneficial effects of implementing this embodiment are as follows: first, the peripheral operation status is obtained, and the peripheral operation status includes a no-input status; then, the no-input status is timed to obtain the duration of the no-input status; then, based on the duration of the no-input status, it is determined whether the duration of the no-input status is greater than a preset sleep time threshold; if the duration of the no-input status is greater than the preset sleep time threshold, the computer's underlying API is called to execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering a sleep state; the computer can be effectively prevented from entering a sleep state, reducing manual operations and avoiding the investment in physical equipment, and can effectively avoid the situation where the computer cannot be used due to sleep, and can be implemented without relying on external hardware devices, with low dependence; it can be implemented with simple programming, with low cost; it can be deployed and used in Windows XP and subsequent systems, and is easy to deploy; it can be deployed in a variety of application scenarios, such as large-screen advertising display systems, computer systems and server systems for public use such as hotels or government affairs, etc.
[0146] The present invention can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present invention can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present invention can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0147] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0148] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0149] Embodiment 2
[0150] Further references Figure 3 , as a response to the above Figure 2 The present invention provides an embodiment of a computer anti-sleep device, and the device embodiment is Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0151] like Figure 3 As shown, the computer anti-sleep device 50 of this embodiment includes: an acquisition module 51, a timing module 52, a processing module 53 and a simulation module 54. Among them:
[0152] An acquisition module 51 is used to acquire the peripheral operation state, where the peripheral operation state includes a no-input state;
[0153] A timing module 52, used for timing the no-input state to obtain a duration of the no-input state;
[0154] The processing module 53 is used to determine whether the duration of the no-input state is greater than a preset sleep time threshold according to the duration of the no-input state;
[0155] The simulation module 54 is used to call the computer's underlying API and execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering a sleep state if the duration of the no-input state is greater than a preset sleep time threshold.
[0156] In this embodiment, the acquisition module 51 further includes:
[0157] A thread module 511 is used to start a thread, and the thread is used to monitor the operating status of the peripheral device;
[0158] The recording module 512 is used to record the no-input state of the peripheral device if there is no input of the peripheral device.
[0159] In this embodiment, the timing module 52 further includes:
[0160] A first start module 521, used to start a first timer, the first timer is used to record the duration of the no-input state;
[0161] The storage module 522 is used to refresh and store the duration of the no-input state at a preset frequency.
[0162] In this embodiment, the processing module 53 further includes:
[0163] A comparison module 531 is used to compare the duration of the no-input state with a preset sleep time threshold;
[0164] The output module 532 is used to obtain the result of comparing the duration of the no-input state with a preset sleep time threshold.
[0165] In this embodiment, the simulation module 54 further includes:
[0166] The mouse movement simulation module 541 is used to call the keyboard mouse movement API instruction SendInput if the duration of the no input state is greater than a preset sleep time threshold;
[0167] The mouse button simulation module 542 is used to call the mouse button API instruction mouse_event to prompt the computer to trigger a keyboard and mouse operation interrupt.
[0168] In some optional implementations of this embodiment, the computer anti-sleep device 50 of this embodiment further includes:
[0169] A second start module 55 is used to start a second timer, and the second timer is used to record the time of virtual instructions simulating real keyboard and mouse operations;
[0170] The stop module 56 is used to stop executing the virtual instruction to simulate the real keyboard and mouse operation when the time of simulating the real keyboard and mouse operation is equal to the simulation operation threshold.
[0171] The beneficial effects of implementing this embodiment are as follows: first, the peripheral operation status is obtained, and the peripheral operation status includes a no-input status; then, the no-input status is timed to obtain the duration of the no-input status; then, based on the duration of the no-input status, it is determined whether the duration of the no-input status is greater than a preset sleep time threshold; if the duration of the no-input status is greater than the preset sleep time threshold, the computer's underlying API is called to execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering a sleep state; the computer can be effectively prevented from entering a sleep state, reducing manual operations and avoiding the investment in physical equipment, and can effectively avoid the situation where the computer cannot be used due to sleep, and can be implemented without relying on external hardware devices, with low dependence; it can be implemented with simple programming, with low cost; it can be deployed and used in Windows XP and subsequent systems, and is easy to deploy; it can be deployed in a variety of application scenarios, such as large-screen advertising display systems, computer systems and server systems for public use such as hotels or government affairs, etc.
[0172] Embodiment 3
[0173] To solve the above technical problems, the embodiment of the present invention also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0174] The above-mentioned computer device 6 includes a memory 61, a processor 62, and a network interface 63 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 6 having components of a memory 61, a processor 62, and a network interface 63, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to a microprocessor, an application specific integrated circuit (ASIC), a programmable gate array (FPGA), a digital processor (DSP), an embedded device, etc.
[0175] The computer device may be a desktop computer, a notebook computer, a PDA, a cloud server, etc. The computer device may interact with the user through a keyboard, a mouse, a remote control, a touch pad, or a voice control device.
[0176] The memory 61 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 61 may be an internal storage unit of the computer device 6, such as a hard disk or memory of the computer device 6. In other embodiments, the memory 61 may also be an external storage device of the computer device 6, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. equipped on the computer device 6. Of course, the memory 61 may also include both the internal storage unit of the computer device 6 and its external storage device. In this embodiment, the memory 61 is generally used to store the operating system and various application software installed on the computer device 6, such as computer-readable instructions of the computer anti-sleep method, etc. In addition, the memory 61 can also be used to temporarily store various types of data that have been output or are to be output.
[0177] The processor 62 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 62 is generally used to control the overall operation of the computer device 6. In this embodiment, the processor 62 is used to run the computer-readable instructions stored in the memory 61 or process data, such as running the computer-readable instructions of the computer anti-sleep method.
[0178] The network interface 63 may include a wireless network interface or a wired network interface. The network interface 63 is generally used to establish a communication connection between the computer device 6 and other electronic devices.
[0179] The beneficial effects of implementing this embodiment are as follows: first, the peripheral operation status is obtained, and the peripheral operation status includes a no-input status; then, the no-input status is timed to obtain the duration of the no-input status; then, based on the duration of the no-input status, it is determined whether the duration of the no-input status is greater than a preset sleep time threshold; if the duration of the no-input status is greater than the preset sleep time threshold, the computer's underlying API is called to execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering a sleep state; the computer can be effectively prevented from entering a sleep state, reducing manual operations and avoiding the investment in physical equipment, and can effectively avoid the situation where the computer cannot be used due to sleep, and can be implemented without relying on external hardware devices, with low dependence; it can be implemented with simple programming, with low cost; it can be deployed and used in Windows XP and subsequent systems, and is easy to deploy; it can be deployed in a variety of application scenarios, such as large-screen advertising display systems, computer systems and server systems for public use such as hotels or government affairs, etc.
[0180] Embodiment 4
[0181] The present invention also provides another embodiment, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the computer anti-sleep method as described above.
[0182] The beneficial effects of implementing this embodiment are as follows: first, the peripheral operation status is obtained, and the peripheral operation status includes a no-input status; then, the no-input status is timed to obtain the duration of the no-input status; then, based on the duration of the no-input status, it is determined whether the duration of the no-input status is greater than a preset sleep time threshold; if the duration of the no-input status is greater than the preset sleep time threshold, the computer's underlying API is called to execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering a sleep state; the computer can be effectively prevented from entering a sleep state, reducing manual operations and avoiding the investment in physical equipment, and can effectively avoid the situation where the computer cannot be used due to sleep, and can be implemented without relying on external hardware devices, with low dependence; it can be implemented with simple programming, with low cost; it can be deployed and used in Windows XP and subsequent systems, and is easy to deploy; it can be deployed in a variety of application scenarios, such as large-screen advertising display systems, computer systems and server systems for public use such as hotels or government affairs, etc.
[0183] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the various embodiment methods of the present invention.
[0184] Obviously, the embodiments described above are only some embodiments of the present invention, rather than all embodiments. The preferred embodiments of the present invention are given in the accompanying drawings, but they do not limit the patent scope of the present invention. The present invention can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present invention more thorough and comprehensive. Although the present invention has been described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific embodiments, or to perform equivalent replacements for some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of the present invention, directly or indirectly used in other related technical fields, is also within the scope of patent protection of the present invention.
Claims
1. A computer anti-sleep method, wherein the computer is provided with a peripheral device, characterized in that: The steps include: Acquire the peripheral operation state, where the peripheral operation state includes a no-input state; Timing the no-input state to obtain a no-input state duration; According to the no-input state duration, determining whether the no-input state duration is greater than a preset sleep time threshold; If the duration of the no-input state is greater than a preset sleep time threshold, the computer bottom layer API is called to execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering a sleep state.
2. The computer anti-sleep method according to claim 1, characterized in that: The step of obtaining the peripheral operation state, wherein the peripheral operation state includes a no-input state, specifically comprises: Start a thread, where the thread is used to monitor the operating status of the peripheral device; If the peripheral device has no input, the no-input state of the peripheral device is recorded.
3. The computer anti-sleep method according to claim 1, characterized in that: The step of timing the no-input state to obtain the duration of the no-input state specifically includes: Starting a first timer, wherein the first timer is used to record the duration of the no-input state; The no-input state duration is updated and stored at a preset frequency.
4. The computer anti-sleep method according to claim 1, characterized in that: The step of judging whether the duration of the no-input state is greater than a preset sleep time threshold according to the duration of the no-input state specifically includes: Comparing the no-input state duration with the preset sleep time threshold; A result of comparing the no-input state duration with the preset sleep time threshold is obtained.
5. The computer anti-sleep method according to claim 1, characterized in that: If the duration of the no input state is greater than a preset sleep time threshold, the steps of calling the computer bottom layer API, executing virtual instructions to simulate real keyboard and mouse operations, and preventing the computer from entering the sleep state specifically include: If the duration of the no-input state is greater than a preset sleep time threshold, calling the keyboard and mouse movement API instruction SendInput; The mouse button API instruction mouse_event is called to prompt the computer to trigger a keyboard and mouse operation interrupt.
6. The computer anti-sleep method according to any one of claims 1 to 5, characterized in that: If the duration of the no-input state is greater than a preset sleep time threshold, the computer underlying API is called to execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering a sleep state, and the method further includes: Starting a second timer, the second timer is used to record the time for which the virtual command simulates the real keyboard and mouse operation; When the time of simulating the real keyboard and mouse operation is equal to the simulation operation threshold, the execution of the virtual instruction to simulate the real keyboard and mouse operation is stopped.
7. A computer anti-sleep device, characterized in that: include: An acquisition module, used for acquiring the peripheral operation state, wherein the peripheral operation state includes a no-input state; A timing module, used for timing the no-input state to obtain a duration of the no-input state; A processing module, configured to determine whether the duration of the no-input state is greater than a preset sleep time threshold according to the duration of the no-input state; The simulation module is used to call the computer bottom API and execute virtual instructions to simulate real keyboard and mouse operations to prevent the computer from entering the sleep state if the duration of the no-input state is greater than a preset sleep time threshold.
8. The computer anti-sleep device according to claim 7, characterized in that: The simulation module comprises: A mouse movement simulation module, used for calling the keyboard and mouse movement API instruction SendInput if the duration of the no-input state is greater than a preset sleep time threshold; The mouse button simulation module is used to call the mouse button API instruction mouse_event to prompt the computer to trigger a keyboard and mouse operation interrupt.
9. A computer device, comprising a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the computer anti-sleep method according to any one of claims 1 to 6 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the computer anti-sleep method according to any one of claims 1 to 6 are implemented.
