I need some help with just a small bit of code, I've been struggling for a while now with this and would love it if someone could help me out. So, when a user (myself, as I'm not distributing) right clicks or left clicks, either "10000" or "10001" respectively, are added to a listbox. However, as you can see why in the code below, the integers indicating a right or a left click (10000/10001) are listed multiple times because, each time the timer ticks, the r/l click is recorded if the buttons are pressed down. Even when I'm clicking my mouse normally, it will list "10000" 6 times, for example, because the timer interval is so fast (10ms).
So basically I need to ensure that only one of these integers are added (i.e. only the actual event of pressing down on r/l mouse buttons is listed, rather than recording if it is pressed down every 10ms.
Here is the code I've got so far:
<pre> Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10
Dim Mouse_LeftClick As Boolean
Dim Mouse_RightClick As Boolean
Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick
Mouse_LeftClick = GetAsyncKeyState(Keys.LButton)
If Mouse_LeftClick Then
Mouse_RightClick = GetAsyncKeyState(Keys.RButton)
If Mouse_RightClick Then
That about sums it up, I hope you understand my problem and thanks so much in advance! :) Also, I'm trying to get better at this language, if you notice anything wrong with how I've formatted the code, please tell me (e.g. is there too much white-space, is it easy to understand)!
What I have tried:
I've tried making it so that in the first 10 or so items in the listbox, only 1 click can exist, but this simply is not practical, especially considering the speed of the timer. :|