Hi there!

Been reading the forums for a while, very good comunity and tremendous help for a lot of things ive been doing. Although i'm having problems with a small issue at the moment.

I found a post HERE that should help me, but having tried it its not really working well at all for the job.

I may be doing something wrong, but i don't think so. Using pnish's code a little way down the page it thinks i'm pressing enter even when im clicking the mouse, sometimes it will get it right but a lot of the time not. I need this to be accurate as for every click of this command button im counting.

In fact this is just for a little game ive been asked to make for demonstration. It sounded really simple. The idea is you must click the button as many times as you can in 10 seconds, but cheating is possible if you just hold down enter.

I have the whole thing working at the moment apart from the cheat prevention:

VB Code:
  1. Private Sub cmdStart_Click()
  2.     Timer1.Interval = 1000
  3.     txttimer.Text = "10"
  4.     cmdClicker.Visible = True
  5.     cmdStart.Visible = False
  6. End Sub
  7.  
  8. Private Sub Form_Load()
  9.   txtcounter.Text = 0
  10.   cmdClicker.Visible = False
  11.   cmdNext.Visible = False
  12. End Sub
  13. Private Sub Timer1_Timer()
  14.      If txttimer.Text = 0 Then
  15.           Timer1.Enabled = False
  16.         cmdClicker.Visible = False
  17.         cmdNext.Visible = True
  18.      Else
  19.           txttimer.Text = txttimer.Text - 1
  20.      End If
  21. End Sub
  22.  
  23. Private Sub cmdclicker_click()
  24.   txtcounter.Text = txtcounter.Text + 1
  25. End Sub

Heres what should work using the [RESOLVED] code from pnish:

VB Code:
  1. Dim MouseClicked As Boolean
  2.  
  3. Private Sub cmdclicker_Click()
  4.  
  5.     If Not MouseClicked Then    ' Assume the user pressed enter
  6.         MsgBox ("cheat")
  7.         Exit Sub
  8.     Else
  9.         '
  10.         '   Do your button-click stuff here
  11.         '
  12.         txtcounter.Text = txtcounter.Text + 1
  13.         MouseClicked = False
  14.     End If
  15.     End Sub
  16.  
  17. Private Sub Cmdclicker_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  18.     '
  19.     '   Flag that the mouse button has been pressed
  20.     '   (May want to check for left or right button etc)
  21.     '
  22.     MouseClicked = True
  23.  
  24. End Sub
  25.  
  26. Private Sub cmdclicker_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  27.     '
  28.     '   Flag that the mouse button has been released
  29.     '   (May want to check for left or right button etc)
  30.     '
  31.     If MouseClicked = True Then
  32.         MouseClicked = False
  33.     End If
  34.     End Sub
  35.    
  36. Private Sub cmdStart_Click()
  37.     Timer1.Interval = 1000
  38.     txttimer.Text = "10"
  39.     cmdClicker.Visible = True
  40.     cmdStart.Visible = False
  41. End Sub
  42.  
  43. Private Sub Form_Load()
  44.   txtcounter.Text = 0
  45.   cmdClicker.Visible = False
  46.   cmdNext.Visible = False
  47. End Sub
  48. Private Sub Timer1_Timer()
  49.      If txttimer.Text = 0 Then
  50.           Timer1.Enabled = False
  51.         cmdClicker.Visible = False
  52.         cmdNext.Visible = True
  53.      Else
  54.           txttimer.Text = txttimer.Text - 1
  55.      End If
  56. End Sub

Just wondered if in any way you masterminds can shed some light on the problem. I must be missing something very trivial, its so simple yet so hard.

Thanks for any help!!!!

Mathew

PS. If you want me to actually post the program, i'm very willing to do so!