|
-
Feb 26th, 2000, 05:05 AM
#1
Thread Starter
New Member
how can i detect which button was clicked on the mose to put in a click event?
-
Feb 26th, 2000, 08:29 AM
#2
So Unbanned
MouseDown
use the
CommandButton MouseDown event
then Button refers to the button pushed
-
Feb 26th, 2000, 10:12 AM
#3
Thread Starter
New Member
but i am making my own control and need to know how to make my own click event that has this:
Event IconClicked(button as integer)
and i need to know how to detect the button on the mouse that was clicked (either right or left) in the RaiseEvent function. I do not know how to raise the event and get the button which was pressed like this:
Public Sub Timer1_Timer()
RaiseEvent IconClicked(which button was clicked)
End Sub
thankyou
Edited by srhutch on 02-26-2000 at 10:14 PM
-
Feb 26th, 2000, 12:52 PM
#4
New Member
Mouse Down event
On a mouse down or mouse up event VB returns a value for the variable 'button'
If button = 1 then the left button was pushed
If button = 2 then the right button was pushed
If button = 3 then the centre button was pushed
I used this last week and it works great. I'm reasonably sure that the values are correct. I mas=y have them mixed up. Check them out
-
Feb 26th, 2000, 01:03 PM
#5
PowerPoster
If you feel confused when due with all the number, why not using this:
vbRightButton
vbMiddleButton
vbLeftButton
-
Nov 1st, 2000, 03:36 AM
#6
Frenzied Member
srhutch:
I don't understand why they didn't make "Button" available to Click() as well. Just make a dim called MouseButton:
Code:
'FORM DECLARATION
Dim MouseButton As Integer
'MOUSEDOWN EVENT
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then 'LEFT BUTTON
MouseButton = 1
ElseIf Button = 2 Then 'RIGHT BUTTON
MouseButton = 2
ElseIf Button = 4 Then 'MIDDLE BUTTON
MouseButton = 4
End If
End Sub
Private Sub Command1_Click()
If MouseButton = 1 Then
'CODE FOR LEFT CLICK
ElseIf MouseButton = 2 Then
'RIGHT CLICK
ElseIf MouseButton = 4 Then
'MIDDLE CLICK
End If
End Sub
-
Nov 1st, 2000, 07:39 AM
#7
Use the GetAsyncKeyState api function to do it.
Code:
Private Declare Function GetAsyncKeyState _
Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbLeftButton) Then Caption = "Left Button"
If GetAsyncKeyState(vbMiddleButton) Then Caption = "Middle Button"
If GetAsyncKeyState(vbRightButton) Then Caption = "Right Button"
End Sub
-
Nov 1st, 2000, 08:59 AM
#8
Frenzied Member
srhutch:
The only problem you may face with this popular API method is that it will be initialized to the value of the left button as soon as the program starts. You may or may not want this to be the case. The way I understood it, you wanted to raise a special event depending on which button clicks a certain control.
-
Nov 1st, 2000, 10:19 AM
#9
Frenzied Member
I'm sorry wey97, but why would you use the Click event if you first use the KeyDown event? Why not put it in the KeyDown then 
also, you can shorten this part:
Code:
If Button = 1 Then 'LEFT BUTTON
MouseButton = 1
ElseIf Button = 2 Then 'RIGHT BUTTON
MouseButton = 2
ElseIf Button = 4 Then 'MIDDLE BUTTON
MouseButton = 4
End If
'to this :)
MouseButton = Button
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 1st, 2000, 10:28 AM
#10
transcendental analytic
BTW, if you press multiple button you will get mixed flag values for button so you need to check for these bit's independently using and operator:
Code:
If MouseButton And 1 Then
'CODE FOR LEFT CLICK
ElseIf MouseButton And 2 Then
'RIGHT CLICK
ElseIf MouseButton And 4 Then
'MIDDLE CLICK
End If
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 1st, 2000, 08:56 PM
#11
I notice that everyone is using 4 as the Middle Button. What does that make 3?
-
Nov 1st, 2000, 10:29 PM
#12
Frenzied Member
The button is a bit field with bits corresponding to the left button (bit 0), the right button (bit 1), and the middle button (bit 2). This refers to the binary representation of 1, 2, and 4. For example, 001 represents the left button, 010 represents the right button, and 100 represents the middle button.
Code:
001 010 100
bit 0 bit 1 bit 2
1 2 4
left right middle
I hope that clears it up.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|