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:
Private Sub cmdStart_Click() Timer1.Interval = 1000 txttimer.Text = "10" cmdClicker.Visible = True cmdStart.Visible = False End Sub Private Sub Form_Load() txtcounter.Text = 0 cmdClicker.Visible = False cmdNext.Visible = False End Sub Private Sub Timer1_Timer() If txttimer.Text = 0 Then Timer1.Enabled = False cmdClicker.Visible = False cmdNext.Visible = True Else txttimer.Text = txttimer.Text - 1 End If End Sub Private Sub cmdclicker_click() txtcounter.Text = txtcounter.Text + 1 End Sub
Heres what should work using the [RESOLVED] code from pnish:
VB Code:
Dim MouseClicked As Boolean Private Sub cmdclicker_Click() If Not MouseClicked Then ' Assume the user pressed enter MsgBox ("cheat") Exit Sub Else ' ' Do your button-click stuff here ' txtcounter.Text = txtcounter.Text + 1 MouseClicked = False End If End Sub Private Sub Cmdclicker_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) ' ' Flag that the mouse button has been pressed ' (May want to check for left or right button etc) ' MouseClicked = True End Sub Private Sub cmdclicker_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) ' ' Flag that the mouse button has been released ' (May want to check for left or right button etc) ' If MouseClicked = True Then MouseClicked = False End If End Sub Private Sub cmdStart_Click() Timer1.Interval = 1000 txttimer.Text = "10" cmdClicker.Visible = True cmdStart.Visible = False End Sub Private Sub Form_Load() txtcounter.Text = 0 cmdClicker.Visible = False cmdNext.Visible = False End Sub Private Sub Timer1_Timer() If txttimer.Text = 0 Then Timer1.Enabled = False cmdClicker.Visible = False cmdNext.Visible = True Else txttimer.Text = txttimer.Text - 1 End If 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!




Reply With Quote