Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 11th, 2004, 11:30 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Mouse-Keyboard Combinations

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!
 
Old February 11th, 2004, 12:15 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

keypress event

 
Old February 11th, 2004, 01:56 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
 
Old February 11th, 2004, 04:46 PM
Authorized User
 
Join Date: Oct 2003
Location: , , New Zealand.
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old February 11th, 2004, 06:21 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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




Similar Threads
Thread Thread Starter Forum Replies Last Post
keyboard handling mojman Assembly Language 0 December 27th, 2007 10:01 PM
How to control mouse and keyboard in C# nhutcmos C# 2005 1 October 1st, 2007 02:18 PM
Mouse and Keyboard Control jared314 Beginning VB 6 2 March 19th, 2007 04:54 PM
Create All Possible Combinations From Varying Sets DolphinBay ASP.NET 1.0 and 1.1 Professional 7 April 26th, 2005 10:55 AM
Hooking the keyboard aliarifpk General .NET 1 March 14th, 2004 10:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.