Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to redefine a mouse button click

Status
Not open for further replies.

lmarles

Technical User
Dec 8, 2000
25
0
0
CA
I have a program that gets data from a weigh scale and puts the data into an Access database. Presently, the user must press the 'F12' key to retrieve the data from the scale. There are a number of text boxes that accept the data from the scale and the user 'tabs' to the next box after each 'F12'. The user would like to use the left mouse button to function as the 'tab' key and the right mouse button to function as the 'F12' key. How can I do this?
 
guess you could use form_mousedown or form_mouseup and have an if/then or select case statement for each button, then sendkey to make it tab and/or f12
if button=1 then sendkeys f12 (syntax not right)
i dont know if it would work or not, but it might be worth a try
 
Thanks dragnut.

My form has a frame and the text boxes are in the frame. As long as the mouse pointer is outside of the frame the following code works. If the mouse pointer is inside the frame then the mouse buttons work as per normal. I would like the code to work even if the mouse pointer is inside the frame. Any suggestions?
Here's the code:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
' MsgBox "Lefthand mouse button pressed"
SendKeys "{tab}"
Button = 0
ElseIf Button = 2 Then
' MsgBox "Righthand mouse button pressed"
SendKeys "{F12}"
Button = 0
End If
End Sub
 
The event will fire only if you click the form because that is where the code is set to fire. If you want it to only click on the text boxes then you have to put that code in each one of your text boxes.

If you want the event to fire anywhere you click then you have to go into WinAPI's.
[tt]
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
' MsgBox "Lefthand mouse button pressed"
SendKeys "{tab}"
Button = 0
ElseIf Button = 2 Then
' MsgBox "Righthand mouse button pressed"
SendKeys "{F12}"
Button = 0
End If
End Sub

Private Sub Text2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
' MsgBox "Lefthand mouse button pressed"
SendKeys "{tab}"
Button = 0
ElseIf Button = 2 Then
' MsgBox "Righthand mouse button pressed"
SendKeys "{F12}"
Button = 0
End If
End Sub
[/tt]
ETC.... Craig, mailto:sander@cogeco.ca

Si hoc legere scis, nimis eruditionis habes
 
The best solution would be to allow the user to click anywhere but I don't know how to use WinAPIs. Can you help me with that? Otherwise, I can use the frame instead of the form and that may be ok. Using the frame the code looks like this:

Private Sub fraFrame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
' MsgBox "Lefthand mouse button pressed"
SendKeys "{tab}"
Button = 0
ElseIf Button = 2 Then
' MsgBox "Righthand mouse button pressed"
SendKeys "{F12}"
Button = 0
End If
End Sub
 
CraigSander,

Actually, having the event fire when in the text boxes would be good. The problem I'm having now is that the text boxes are an array (Text(0) thru Text(18)) so I get a "Compiler error: Expected: identifier" when I use the following code:

Private Sub Text(0)_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
' MsgBox "Lefthand mouse button pressed"
SendKeys "{tab}"
Button = 0
ElseIf Button = 2 Then
' MsgBox "Righthand mouse button pressed"
SendKeys "{F12}"
Button = 0
End If
End Sub
 
Ok, I've figured out how to handle the text box array. So my code will include MouseDown checks for the form, frame, and text boxes.

Private Sub form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
' MsgBox "Lefthand mouse button pressed"
SendKeys "{tab}"
Button = 0
ElseIf Button = 2 Then
' MsgBox "Righthand mouse button pressed"
SendKeys "{F12}"
Button = 0
End If
End Sub

Private Sub fraFrame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
' MsgBox "Lefthand mouse button pressed"
SendKeys "{tab}"
Button = 0
ElseIf Button = 2 Then
' MsgBox "Righthand mouse button pressed"
SendKeys "{F12}"
Button = 0
End If
End Sub

Private Sub Text_MouseDown(Index as Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Index => 0 and Index < 19 then
If Button = 1 Then
' MsgBox &quot;Lefthand mouse button pressed&quot;
SendKeys &quot;{tab}&quot;
Button = 0
ElseIf Button = 2 Then
' MsgBox &quot;Righthand mouse button pressed&quot;
SendKeys &quot;{F12}&quot;
Button = 0
End If
End If
End Sub

Thanks for your help everyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top