Results 1 to 10 of 10
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Mouse click Ctrl combination

    Normally, when I want to test for a combination action of mouse-click and Ctrl key, I would simply use [Event Procedure] as the "On Mouse Down" property setting for a control. Is there a way I can test for the combined action if I want to substitute my own function in place of the [Event Procedure]? E.g., "=MyFunction(argument)". The application is a form with a lot of similar controls where I need to provide multiple functionality with each click without having to have an equal quantity of [Event Procedure]s. I.e., if the control is clicked I do "A" but if the Ctrl key is also down I do "B".

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    in the MOUSEDOWN event:

    Code:
    Private Sub Text0_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Select Case Shift
      Case 0  'no key pressed
        txtbox = "A"
        
      Case 2  'Ctl
        txtbox = "B"
        
      Case 4  'alt
    End Select
    End Sub
    
    


  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    An approach I'm trying to avoid. If I have 60 controls where I want to provide dual functionality, your approach would require 60 Mouse Down subs. (I could accomplish the task with a click versus a double-click but the user has requested the use of the Ctrl-click combination.)

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If you can apply this to a record selector, then you should be able to use one event - at the form level. However I'll bet this is not the case. In the case of 60 controls and this was a work colleague asking my answer would be no to including ctrl. If this is a paying customer, my answer would be 'sure, but it's going to add to the bill' - because I'm betting there is no way to pass the mouse button value by using a UDF. When you call a udf as the response to a user action, you must pass the function arguments if any are involved. What would you pass to your udf for the button value even if you could? Even if passing a button value is possible, you don't know which value to use. I have to wonder what is so different about ctrl click vs double click that the latter cannot be used.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I have to wonder what is so different about ctrl click vs double click that the latter cannot be used.
    I will plead my case, as that is what I wanted to do from the get-go already knowing the limitations in gaining access to SHIFT & BUTTON values. But, since many of the Forum contributors are a lot more knowledgeable than I am about this "off the wall" stuff I'd thought I'd at least ask the question.
    Thanks,
    Bill

  6. #6
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by GraeagleBill View Post
    I will plead my case, as that is what I wanted to do from the get-go already knowing the limitations in gaining access to SHIFT & BUTTON values. But, since many of the Forum contributors are a lot more knowledgeable than I am about this "off the wall" stuff I'd thought I'd at least ask the question.
    Thanks,
    Bill
    Hi Bill! Don't give up so soon!... There is a lot of space for your stuff "out of the wall".

    This is a classic case for a class module.

    In general, the basic steps are:
    Create a class module, add the appropriate code and keep in the form (at run time) one instance of this class for each relevant control in a collection.

    Check the attached sample file for further details.
    Open the form, click on "menu" images and see what happen to ControlTipText of each control after each click. Each "menu" control, keeps the count of clicks on it, in its Tag property, via the code of the class, and the "statistics" depends on this property.

    Inspect the code of both form and class module to find out that there is no code repetition at all. The whole functionality of the controls has been keeping in one place (in class module) while the form takes care only for its own functionality and for the creation of the instances of the class for each relevant control.

    I hope it helps you to break your walls down.

    Good luck,
    John
    Attached Files Attached Files

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Isn't the barrier here not being able to know which (if any) mouse button was down during the click event - because Mouse events are the ones that can detect that? Or do you think there is a way with a custom class to capture that?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by Micron View Post
    Isn't the barrier here not being able to know which (if any) mouse button was down during the click event - because Mouse events are the ones that can detect that? Or do you think there is a way with a custom class to capture that?
    Micron, you be right. Seems that the OP is a double question and I have answered only the half.
    I have answered to that part:
    “I need to provide multiple functionality with each click without having to have an equal quantity of [Event Procedure]s.”
    but not to that:
    “Is there a way I can test for the combined action if I want to substitute my own function in place of the [Event Procedure]?”
    So, I am coming back to complete my answer, and, yes, there is a way to capture the state of any key, anywhere in the code, with the assist of the API of OS.
    Well, in case of the attached file in post #6, the code of the class could be something like this:
    Code:
    Option Compare Database
    Option Explicit
    
    #If vba7 Then
        Private Declare PtrSafe Function GetKeyState Lib "user32" Alias "GetKeyState" (ByVal nVirtKey As Long) As Integer
    #Else
        Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    #End If
    
    Private Const KEY_MASK As Integer = &HFF80
    Private Const VK_LSHIFT = &HA0
    Private Const VK_RSHIFT = &HA1
    Private Const VK_LCONTROL = &HA2
    Private Const VK_RCONTROL = &HA3
    [...]
    Private Sub mMenuImage_Click()
    
        If CBool(GetKeyState(VK_LCONTROL) And KEY_MASK) Then
            MsgBox "The Control key is been pressed", vbInformation, mMenuImage.ControlTipText
        End If
    [...]
    Now, I think that I don’t owe something any more to this thread.

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Had to leave this yesterday as things got a bit weird, but saw your post and tested my thought from yesterday. Here's what I think:
    You added a mouse click event as a method of the class but most of it is commented out. So regardless of which image you click on, that event runs and from it, you can tell which control key was pressed. Thus it would seem that the example you posted contains only one written procedure (mouse down) and not one for every control (akin to the 60 controls originally referred to). This is brilliant. I'd say you had already answered both parts of the problem.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by Micron View Post
    Had to leave this yesterday as things got a bit weird, but saw your post and tested my thought from yesterday. Here's what I think:
    You added a mouse click event as a method of the class but most of it is commented out. So regardless of which image you click on, that event runs and from it, you can tell which control key was pressed. Thus it would seem that the example you posted contains only one written procedure (mouse down) and not one for every control (akin to the 60 controls originally referred to). This is brilliant. I'd say you had already answered both parts of the problem.
    Thanks a lot Micron!

    I always appreciate your comments and criticism.

    Cheers,
    John

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Remove Ctrl + Click From Hyperlink
    By DMT Dave in forum Access
    Replies: 5
    Last Post: 03-03-2021, 01:50 AM
  2. Virtual mouse click of button
    By SierraJuliet in forum Programming
    Replies: 14
    Last Post: 01-24-2018, 12:37 PM
  3. Disable Mouse Right Click
    By data808 in forum Access
    Replies: 18
    Last Post: 03-10-2014, 05:58 AM
  4. Replies: 2
    Last Post: 09-06-2011, 04:56 PM
  5. Mouse click to open form
    By darryl.charles in forum Programming
    Replies: 0
    Last Post: 09-05-2008, 10:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums