VB Keyboard Mouse no action to invoke the program _vb

Source: Internet
Author: User

The function I want to implement is to invoke the program when the keyboard has no input, the mouse is not moved, or the action is clicked. The first thought is to use hook hooks to get the keyboard or mouse action, if no action to invoke the program. The result I tried was that there was always a problem with the hook.

Later thought of Windows screen saver is when the keyboard mouse does not move into the screen protection, so change the train of thought, want to make the program in this form, the keyboard Mouse no action, the system into the screen protection, and then detect whether the system runs screen saver, if the operation of the call program. This approach is to use the screen saver as an intermediary, the detection of keyboard and mouse action to the screen saver to complete the work. SystemParametersInfo can implement functions that obtain screen protection information. The reference code is as follows:

' API calls with common definitions:
Private Declare Function systemparametersinfo _
  Lib "User32" _
  Alias "SystemParametersInfoA" _
   (ByVal uiaction As Long, _
    ByVal Uiparam As Long, _
    Pvparam as Any, _
    ByVal Fwinini as Long) as boolean< C8/>private Const spi_getscreensaveactive as Long = &h10  ' screensavers are enabled constants
Private Const Spi_ Getscreensaverrunning as Long = &h72 ' screensavers are running constants

Private Sub Timer1_timer ()
  Dim brunning as Boolean   ' Whether the screensaver runs variables, of course you can define global variables
  SystemParametersInfo spi_getscreensaverrunning, 0, brunning, False ' calling API, Brunning returns the screensaver running state
  Debug.Print time; "Screensaver running ="; Brunning ' Demo: Print screensaver information end
Sub
 
' In addition, to see whether the screensaver is enabled, you can also use the following methods:
SystemParametersInfo Spi_ Getscreensaveactive, 0, bactive, False ' bactive for return value (logical type)

But I do not know why I am under the WIN7 debugging or there is a problem, prompted SystemParametersInfo spi_getscreensaverrunning, 0, Brunning, False
The brunning type in is wrong and can only be dropped.

Finally, the final implementation of the scheme is to use the Getlastinputinfo function to obtain the system's idle time, the reference code is as follows:

Option Explicit
Private Declare Function getlastinputinfo Lib "user32" (Plii as Lastinputinfo) as Boolean
private Declare Function gettickcount Lib "kernel32" () as Long
Private Type lastinputinfo
  cbsize as Long
  dwtime as L Ong End
Type
 
Private Sub Form_Load ()
   timer1.interval = 1000 End  
Sub
 
Private Sub Timer1_timer ()
  Dim lii as lastinputinfo
  lii.cbsize = Len (lii)
  if Getlastinputinfo (lii) Then
    if (gettickcount-lii Dwtime)/60000 >= Then call      
      MsgBox ("Due to no operation in this machine for 15 minutes, if no response after 3 minutes, the system will force shutdown", vbYesNo + vbexclamation + vbdefaultbut Ton2, "hint") End If the end
Sub

The above mentioned is the entire content of this article, I hope you can enjoy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.