954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Dwell Click?

I want to make an application in vb.net which will allow user to use mouse in a different way. i.e Dwell Clicking.

Suppose user moves mouse pointer at particular location and if the user doesnt move the mouse pointer from that location for 2 seconds then single click will be initiated.

Can any one help me out! How should I start?
All I know is I will need a form, 2 buttons i.e for selecting single click and double click, and a timer!

Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

What is Dwell Clicking ?

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

@debasisdas ..The user moves mouse pointer at particular location(dwelling) and if the user doesnt move the mouse pointer from that location for particular time then clicks will be initiated.

Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

1. On a timer keep tacking of the X,Y coordinates of the mouse.
2. Check the same after desired time gap and compare with the old location, if it has changed call the click event.
3. On each mouse move reset the timer.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

@debasisdas.. First I would like to Thank you for your time.
I understood your first step, and successfully implemented it. But, I m stuck in second step i.e checking the new coordinates with old ones for desired time gap? How do I set timer and which data structure should I use? Should I use array, or variables will do? If possible can you post the sample code of second step? - Thank you.

Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

No need of using array ,using variables should work for you.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

Can you post the sample code of second step? - Thank you.

Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

what is the problem with step2 ?

suppose
on start of the timer
x=1500
y=2000

after 2 seconds
x1=2500
y1=3000


if x <> x1 and y <>y1 then
' your next logic here

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

Why not just use the MouseHover event?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Do click code here
    End Sub

    Private Sub Button1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseHover
        Button1_Click(Nothing, Nothing)
    End Sub


MSDN - Control.MouseHover Event

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

Actually that does not give you much control over the dwell time.
Try using a ToolTip control like this.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolTip1.AutomaticDelay = 1500
        ToolTip1.SetToolTip(Button1, "Button1")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Do click code here
        MessageBox.Show("Clicked")
    End Sub

    Private Sub ToolTip1_Popup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PopupEventArgs) Handles ToolTip1.Popup

        If e.AssociatedControl Is Button1 Then
            e.Cancel = True
            Button1_Click(Nothing, Nothing)
        End If

    End Sub
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

I dont want cursor to be able to initiate clicks on form only!

It should initiate clicks anywhere like on desktop, taskbar...etc

Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

I dont want cursor to be able to initiate clicks on form only!

It should initiate clicks anywhere like on desktop, taskbar...etc

Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

Ohh, you mean change the whole OS mouse experience so that you can Dwell click a Desktop shortcut.

That will require very deep knowledge of the OS and is not available via .Net directly.
You will need to do some research on Windows OS messaging and how Windows handles mouse operations. Then call on some Windows APIs.

Sorry, this is a bit beyond my knowledge.
Maybe someone else could help.
Good luck.

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

@debasisdas & @nick.crane - Thank you for helping me!

I have successfully created dwell click application. But, I m facing some problem.
I have used a timer whose interval is set to 2 sec, so this program is initiating clicks every 2 sec. I want it to click only when my mouse does not move for 2 sec or so.

means if I move mouse continuously it should not initiate click.

Please help me out with timer syntax - Thank you!

Public Class Form1
    Dim x As Integer  ' X variable to store x coordinate of cursor
    Dim y As Integer  ' X Variable to store y coordinate of cursor
    Dim x1 As Integer  ' X1 Variable to store x1 new coordinate of cursor
    Dim y2 As Integer   'y2 Variable to store y2 new coordinate of cursor
    Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)

    Private Sub Mouse_Click(ByVal button As Integer, ByVal state As String)
        Select Case button
            Case 1
                If state = "down" Then
                    mouse_event(2, 100, 100, 0, 0)
                Else
                    mouse_event(4, 100, 100, 0, 0)
                End If
            Case 2
                If state = "down" Then
                    mouse_event(8, 100, 100, 0, 0)
                Else
                    mouse_event(16, 100, 100, 0, 0)
                End If
            Case 3
                If state = "down" Then
                    mouse_event(32, 100, 100, 0, 0)
                Else
                    mouse_event(64, 100, 100, 0, 0)
                End If
        End Select

    End Sub

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        x = MousePosition.X
        y = MousePosition.Y
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        x1 = MousePosition.X
        y2 = MousePosition.Y

        If x <> x1 And y <> y2 Then
            Mouse_Click(1, "down")
            Mouse_Click(1, "up")

        End If

        x = x1
        y = y2

    End Sub
Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

Reply..!

Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

You have no code to capture the mouse movement!
Your application will capture mouse events while it has focus.
However, when the user clicks outside your app you will not receive any mouse event notifications.
This is a feature of the OS and you must do more research to find out how to capture the mouse at a lower level. Not sure how you do this. Good luck in finding out.

Also, according to MSDN mouse_event Function the mouse_event is superseded with the SendInput Function .

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

I m trying to make this application http://www.sensorysoftware.com/dwellclicker.html

Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

I presume that you are doing this as an exercise, as the program you linked runs just fine on Win7; and normally re-inventing the wheel is not worth-while.:)

Also, I found this thread DaniWeb - Intercept windows mouse events
which reference this page The Code Project - Processing Global Mouse and Keyboard Hooks in C#

Hope it helps.

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

I dont have problem with mouse clicks!
I just want to control timer! i.e if mouse doesnt move for specific time initiate click. If I continously move my mouse it should not perform clicks!
C'mon guys help me out!

Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

In your code that captures the mouse move event you should reset the timer.
Then when the mouse stops moving your timer is allowed to timeout.
When the timer times out the mouse has been stationary for timeout period.
Try this in the mouse move event handler.

Timer2.Enabled = False;
Timer2.Enabled = True;
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: