Usually you'd use SendMessage() API to send the WM_LBUTTONDOWN message to a hWnd.
Code:
SendMessage myhWnd, WM_LBUTTONDOWN, MK_SHIFT, 0&
The wParam (MK_SHIFT) should reflect the state of the shift, alt or ctrl key.
For some reason I was not able to SendMessage the MK_SHIFT to a VB control.
Try to research more on SendMessage WM_LBUTTONDOWN and th efollowing wParam parameter.
Thank you WoF, MK_SHIFT can even report the status of the keys shifit, ctrl and alt, but what the exact time of sendkeys one of these buttons to simulate a left mouse click and result shift + click or ctrl + click, I can not find these in place, I hope to be able to in VB6, I know that Delphi is possible, I do not have to change the programming language here I'll get it
Quote:
"... but what the exact time of sendkeys one of these buttons to simulate a left mouse click and result shift + click or ctrl + click, I can not find these in place...."
Are you trying to measure the length of time the key has been pressed at a time mouse was also pressed?
Anyway, here is another possible option.
Code:
Option Explicit
'shift state placeholder
Dim kstatus As Integer
' -- save the keyboard/shift state when you press or release them
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
kstatus = Shift
End Sub
Private Sub UserForm_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
kstatus = Shift
End Sub
' Then check the kstatus when you click the mouse. You can also use mouse_down
Private Sub UserForm_Click()
Select Case kstatus
Case 1
MsgBox "Shift pressed"
Case 2
MsgBox "Ctrl pressed"
Case 4
MsgBox "Alt pressed"
Case Else
MsgBox "No shift"
End Select
End Sub
I dont have VB in the pc I am using right now and have not programmed in VB for over 5 years now. But it should be something like that (I used Excel VBA form which is slightly different) in this sample code.
Marketing our skills - please participate in the survey and share your insights -
I understand, the problem is not knowing when a key (shift or ctrl) was pressed, is to simulate pressing shift or control and left click the mouse while
To send a MouseDown to a control or form you use SendMessage like this:
SendMessage hWnd, WM_LBUTTONDOWN, 0&, 0&
where hWnd is the window handle of the control or form.
If you would subclass a windowproc you will find that that the incoming message WM_LBUTTONDOWN is accompanied by two more parameters (wParam and lParam).
wParam would - in case of additional shift keys held down - contain the bits for them
MK_SHIFT (&H4), MK_ALT (&H10) and MK_CONTROL (&H8)
For SendMessage() wParam is the third parameter. So it is to be expected that if you would set the apropriate bits it would cause a shift-click:
SendMessage hWnd, WM_LBUTTONDOWN, MK_SHIFT, 0&
But obviously the shift information is not recognized by the receiving window.
The remaining question is: Why is this?
I did not have time for deeper research yet, sorry. Maybe somebody comes up with an idea now that the facts are explained again.
Thank you for trying to help, we all know how to move the mouse cursor in any direction, giving left click, middle click and right click, but could not find anywhere how to simulate the shift + left click and ctrl + left click, are two types of clicks important, without them a function to simulate mouse is not complete. I hope someone has the answer
I guess you are trying to select a rang of items in a list like in windows explorer or the likes.
**** lets you select between two points ctrl lets you select additional items.
This is some code that does what I think you want to do:
1. It sends a mouse click to position 100,100 on your screen - regardless of the app
2. it simulates a down shift on the "Shift" Key
3. It mouse clicks on position 100,400
4. it releases the **** key
The effect is it selects whatever is between these two points.
Well, that's clever to use the keybd_event() API. Very good.
I tried to use the SendMessage() with WM_KEYDOWN, which did not give the proper results.
Well done.
I' ve tried this in the attached and it seems to work for "shift" at least. It need a sleep or DoEvents call to let the keypress event occur.
I cannot really see any practical way the OP would want to use it unless he was trying to click specific co-ordinates on the desktop rather than to raise click events on a specified control. He
doesn't really make it clear.
Anyway he can do it both ways using this kind of approach.
Yes. Very good.
I really wonder why the SendMessage() with WM_KEYDOWN and the code for the shift key does not produce the same result as a keybd_event() call. I would have expected the same result, but obviously it doesn't do.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.