Results 1 to 30 of 30

Thread: How to detect mouse inactivity in VB.Net ?

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    62

    How to detect mouse inactivity in VB.Net ?

    Hi friends, I have a code and a problem, I would appreciate it if you help. You know that some sites do not process the mouse after a certain period of time to logout the site. I want to prevent a user from typing in a program to refresh the site when the computer is not at the logout .

    If the site is not processed for 5 minutes, check out the site. We create a counter and start it from the last time the mouse was active. 5 minutes before the end of the main page refresh. Then we reboot the meter. These operations continue in a loop. But whenever the mouse moves, we always reset the counter.

    Thank you very much for your help.

    Downloads: https://www.mediafire.com/file/ki6tp...topup.zip/file


    Or codes;

    Code:
    Option Strict On
    Option Explicit On
    Imports System.Runtime.InteropServices
    
    Public Class Form1
        <DllImport("user32.dll")> Shared Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As Boolean
        End Function
    
        <StructLayout(LayoutKind.Sequential)> Structure LASTINPUTINFO
            <MarshalAs(UnmanagedType.U4)> Public cbSize As Integer
            <MarshalAs(UnmanagedType.U4)> Public dwTime As Integer
        End Structure
    
        Dim lastInputInf As New LASTINPUTINFO()
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Timer1.Interval = 1000
            Timer1.Start()
            WebBrowser1.Navigate("https://etopup.vodafone.com.tr/ETOPUPGUI/")
        End Sub
    
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            WebBrowser1.Document.GetElementById("userLoginForm:userName").SetAttribute("value", My.Settings.username)
            WebBrowser1.Document.GetElementById("userLoginForm:userPassword").SetAttribute("value", My.Settings.password)
    
        End Sub
    
        Private Sub KullanıcıAdıVeŞifreKaydetToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KullanıcıAdıVeŞifreKaydetToolStripMenuItem.Click
            Form2.ShowDialog()
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            lastInputInf.cbSize = Marshal.SizeOf(lastInputInf)
            lastInputInf.dwTime = 0
            GetLastInputInfo(lastInputInf)
            'ToolStripStatusLabel1.Text = "Inactivity Time: " & CInt((Environment.TickCount - lastInputInf.dwTime) / 1000).ToString
            If CInt((Environment.TickCount - lastInputInf.dwTime) / 10000) > 10 Then 'check if it has been 60 seconds
                'Do whatever commands here that you want to happen
                'if no user input is detected in last 60 seconds.
                WebBrowser1.Document.All("j_id5:mainPage_image1").InvokeMember("click")
    
                'ToolStripStatusLabel1.Text = CStr(CInt((Environment.TickCount - lastInputInf.dwTime)))
                'ToolStripStatusLabel1.Text = CStr(Marshal.SizeOf(lastInputInf))
    
            End If
            Timer1.Start()
        End Sub
    End Class
    Last edited by Enigmatic; Jul 30th, 2019 at 09:53 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width