Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 October 25th, 2006, 10:33 AM
Registered User
 
Join Date: Oct 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to gelias
Default How to capture compound keypress, e.g. Ctrl-P

-What is the proper way to capture the keypress of 'Ctrl-P', for example.
-I can capture a single keypress this way:
If (KeyEventArgs.KeyCode = Keys.P) Then
--{pressing 'P' triggers the event}
-But what about 'Ctrl-P'? I've tried
If (KeyEventArgs.KeyCode = Keys.ControlKey And Keys.P) Then
--{Just pressing the Ctrl key triggers the event(?!), which is not what I need.}
Thanx



 
Old October 25th, 2006, 10:45 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If e.KeyChar = Microsoft.VisualBasic.ChrW(15) Then MessageBox.Show("Ctrl-P pressed")

I *think* it is ChrW(15) it might be ChrW(16) but that is how you would detect it.


-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 25th, 2006, 12:04 PM
Registered User
 
Join Date: Oct 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to gelias
Default

Thanx.
I finally found the solution I want by stumbling on the right combo in the VS2005 help (search KeyDown not KeyPress), to wit:
If (e.KeyCode = Keys.P And e.Modifiers = Keys.Control) Then
   {this works for Ctrl-P as expected!!}
NOTE: One of my problems was that I was trying to use Keys.ControlKey instead of Keys.Control. Only the latter will work with e.Modifiers.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Compound Select Statements mphare XSLT 4 October 14th, 2008 10:31 PM
keypress umeshtheone Beginning VB 6 0 June 9th, 2007 12:38 AM
on KeyPress Help higgo23 Access VBA 3 October 5th, 2006 07:08 AM
Keypress Event bharatsaboo VB.NET 2002/2003 Basics 0 February 25th, 2005 03:34 AM





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