Quantcast
Channel: Handling mouse movements..
Viewing all articles
Browse latest Browse all 6

Handling mouse movements..

$
0
0
What if user runs the application without moving the mouse, I mean with keyboard

One Example, One Form  and paste the following code

Public Class Form1
    Dim st As New Stopwatch
    Private WithEvents bw As New System.ComponentModel.BackgroundWorker
    Private UsingAgain As Boolean = False
    Private SecondToWaitFor As Integer = 5
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
        bw.WorkerSupportsCancellation = True
        AddHandler Application.Idle, AddressOf Application_Idle
        st.Start()
    End Sub
    Private Sub Application_Idle()
        If st.Elapsed.Seconds > SecondToWaitFor AndAlso Not bw.IsBusy Then
            bw.RunWorkerAsync()
        End If
    End Sub

    Private Sub SomeLengthyTask() Handles bw.DoWork
        While Not bw.CancellationPending
            Debug.WriteLine("Doing Work")
            Threading.Thread.Sleep(1000)
        End While
    End Sub


    Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseMove
        st = Stopwatch.StartNew()
        bw.CancelAsync()
    End Sub

    Private Sub Form1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        st = Stopwatch.StartNew()
        bw.CancelAsync()
    End Sub
End Class


Arjun Paudel

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>