Did I cllick the left or right button?

Discussion in 'AutoCAD' started by Dave F., May 10, 2004.

  1. Dave F.

    Dave F. Guest

    Hi
    A2k2

    I want to test for three events when selecting an entity:

    1. Left button - entity selected
    2.Left Button - entity missed
    3.right button.

    The routine below (from vbdesign website) almost works, but 2 & 3 both end
    up at the chevroned line(>>).
    How can I test for a right click?

    Unfortunately, I;m lost when it comes to

    Public Function EntSel(strPrmt As String) As AcadEntity
    Dim objTemp As AcadEntity
    Dim objUtil As AcadUtility
    Dim varPnt As Variant
    Dim varCancel As Variant
    On Error GoTo Err_Control
    Set objUtil = ThisDrawing.Utility
    objUtil.GetEntity objTemp, varPnt, strPrmt
    Set EntSel = objTemp
    Exit_Here:
    Exit Function
    Err_Control:
    Select Case Err.Number
    Case -2147352567
    varCancel = ThisDrawing.GetVariable("LASTPROMPT")
    If InStr(1, varCancel, "*Cancel*") <> 0 Then
    If GetAsyncKeyState(VK_ESCAPE) And 8000 > 0 Then
    Err.Clear
    Resume Exit_Here
    ElseIf GetAsyncKeyState(VK_LBUTTON) > 0 Then
    Err.Clear
    Resume
    End If
    Else
    'Missed the pick, send them back!End If
    Case Else
    MsgBox Err.Description
    Resume Exit_Here
    End Select
    End Function
     
    Dave F., May 10, 2004
    #1
  2. Dave F.

    bcoward Guest

    Dave,

    presently your not doing anything to check for right mouse button. Work the foloowing virtual key into your routine for right mouse button.

    VK_RBUTTON - Right mouse button

    Good luck,

    Bob Coward
    CADS, Inc

    800-366-0946
     
    bcoward, May 10, 2004
    #2
  3. Dave F.

    Dave F. Guest

    Hi

    I've managed to get this far, but it's very tempermental how it works.
    Sometimes it will always go down the 'left' route.
    Other (after I've clicked on an object), it works for a while, but if I
    reload it, it fails to work again!

    Any Ideas?
    Thanks in Advance

    Dave F.

    Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long)
    As Integer

    Public Const VK_ESCAPE = &H1B
    Public Const VK_LBUTTON = &H1
    Public Const VK_RBUTTON = &H2

    Sub testEntSel()
    Dim RtnEnt As AcadEntity
    Dim pt As Variant

    On Error GoTo Err_Control
    ThisDrawing.Utility.GetEntity RtnEnt, pt, "Select an Entity to Offset: "
    Debug.Print RtnEnt.ObjectName
    Exit Sub
    Err_Control:
    If GetAsyncKeyState(VK_LBUTTON) Then
    Debug.Print "L"
    ElseIf GetAsyncKeyState(VK_RBUTTON) Then
    Debug.Print "R"
    End If
    End Sub

    the foloowing virtual key into your routine for right mouse button.
     
    Dave F., May 11, 2004
    #3
  4. Try adding the following before you try to get the entity.
     
    Nathan Taylor, May 13, 2004
    #4
  5. Dave F.

    Dave F. Guest

    Thanks for that. It seems to work.

    I'm confused as to why none of the examples I found noted this problem?

    Anyway, Thanks again
    Dave F.
     
    Dave F., May 13, 2004
    #5
  6. No worries Dave. I too find it odd that the examples I have seen don't note this problem.
    Regards - Nathan
     
    Nathan Taylor, May 13, 2004
    #6
  7. I thought that was the final solution but have still been experiencing problems. I worked the following out and found some similar examples.

    Replace

    If GetAsyncKeyState(VK_LBUTTON) Then

    With

    Dim intKeyState as Integer
    intKeyState = GetAsyncKeyState(VK_LBUTTON)
    If intKeyState = -32767 Then

    Regards - Nathan
     
    Nathan Taylor, Jul 12, 2004
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.