|
Subject:
|
Mouse-Keyboard Combinations
|
|
Posted By:
|
shadowpug
|
Post Date:
|
2/11/2004 10:30:08 AM
|
Does someone have sample code in either a mouse click or mouse down event that tests to see if a modifier key such as ALT,CTRL or SHFT is being pressed?
What I want to do is something like:
Sub mouse.Click....
If CTRL is pressed then
Do Something
else
Do something else
End sub
Thanks!
|
|
Reply By:
|
bcmaverik
|
Reply Date:
|
2/11/2004 11:15:02 AM
|
keypress event
|
|
Reply By:
|
shadowpug
|
Reply Date:
|
2/11/2004 12:56:18 PM
|
How? A keypress event is separate from mouse click event. Then you have the reverse problem. How do you know when a mouse button is clicked when a key press event occurs?
|
|
Reply By:
|
Nick.Net
|
Reply Date:
|
2/11/2004 3:46:27 PM
|
Not too sure what you are trying to achieve, but this code seems to work. Keep in mind that for a modifier keypress event to register in this example (SHIFT), a second key has to be pressed (eg "a"), as well as the left mouse button.
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As _ System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If ((Control.ModifierKeys And Keys.Shift) = Keys.Shift) _ And Control.MouseButtons = MouseButtons.Left Then ' Do This Else 'Do That End If End Sub
|
|
Reply By:
|
shadowpug
|
Reply Date:
|
2/11/2004 5:21:39 PM
|
Awesome...
Thanks for pointing me in the right direction...
For others reading this thread....This will work:
Private Sub Button1_Click(ByVal sender As Object,ByVal e as EventArgs) Handles.Button1.Click
If Control.ModifierKeys = Keys.Control Then Do Something Else Do Something Else End If
End Sub
|