473,379 Members | 1,245 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Catching Keyboard buttons (multiple)

How would I be able to capture multiple key presses, such as Alt+Shift+D in
a form's KeyPress and KeyDown events? Thanks in advance.

-Jason
Nov 21 '05 #1
9 6237
Hi,

KeyPress event doesn't expose what modifier keys were pressed.

In KeyDown event, use KetEventArgs.Modifiers, KetEventArgs.Control,
KetEventArgs.Shift & KetEventArgs.Alt properties.

HTH

"OpticTygre" <op********@adelphia.net> wrote in message
news:1r********************@adelphia.com...
How would I be able to capture multiple key presses, such as Alt+Shift+D in
a form's KeyPress and KeyDown events? Thanks in advance.

-Jason

Nov 21 '05 #2
Thanks, I'll give it a whirl.

-Jason

"Shiva" <sh******@online.excite.com> wrote in message
news:e%****************@TK2MSFTNGP15.phx.gbl...
Hi,

KeyPress event doesn't expose what modifier keys were pressed.

In KeyDown event, use KetEventArgs.Modifiers, KetEventArgs.Control,
KetEventArgs.Shift & KetEventArgs.Alt properties.

HTH

"OpticTygre" <op********@adelphia.net> wrote in message
news:1r********************@adelphia.com...
How would I be able to capture multiple key presses, such as Alt+Shift+D
in
a form's KeyPress and KeyDown events? Thanks in advance.

-Jason

Nov 21 '05 #3
Still not working right.

If I do a:

Debug.WriteLine(e.Modifiers = Keys.Control AndAlso e.Modifiers = Keys.Shift)

Then I get a 'false' for the control key, a 'false' for the shift key, and a
'false' for both keys pressed.

If I do a:

Debug.WriteLine(e.Modifiers = Keys.Control OrElse e.Modifiers = Keys.Shift)

Then I get a 'true' for the control key, a 'true' for the shift key, and a
'false' for both keys pressed.

Any ideas?

"Shiva" <sh******@online.excite.com> wrote in message
news:e%****************@TK2MSFTNGP15.phx.gbl...
Hi,

KeyPress event doesn't expose what modifier keys were pressed.

In KeyDown event, use KetEventArgs.Modifiers, KetEventArgs.Control,
KetEventArgs.Shift & KetEventArgs.Alt properties.

HTH

"OpticTygre" <op********@adelphia.net> wrote in message
news:1r********************@adelphia.com...
How would I be able to capture multiple key presses, such as Alt+Shift+D
in
a form's KeyPress and KeyDown events? Thanks in advance.

-Jason

Nov 21 '05 #4
> Debug.WriteLine(e.Modifiers = Keys.Control OrElse e.Modifiers =
Keys.Shift)


'Keys' are bit flags. Use 'Or' to do a bitwise Or. OrElse is a logical
operator not a bitwise operator.

Debug.WriteLine(e.Modifiers = Keys.Control Or e.Modifiers = Keys.Shift)
hope that helps..
Imran.
Nov 21 '05 #5
Sortof. The problem is that I'm trying to catch when the ALT and the SHIFT
or CONTROL key is pressed along with the 'D' key. So something like:

If e.Modifiers = Keys.Alt And (e.modifiers = keys.shift or e.modifiers =
keys.control) And e.KeyCode = keys.D Then do something

The problem is, that code doesn't catch the keys properly.

-Jason

"Imran Koradia" <no****@microsoft.com> wrote in message
news:eO**************@TK2MSFTNGP10.phx.gbl...
Debug.WriteLine(e.Modifiers = Keys.Control OrElse e.Modifiers =

Keys.Shift)


'Keys' are bit flags. Use 'Or' to do a bitwise Or. OrElse is a logical
operator not a bitwise operator.

Debug.WriteLine(e.Modifiers = Keys.Control Or e.Modifiers = Keys.Shift)
hope that helps..
Imran.

Nov 21 '05 #6
try something like this:

If (((e.Alt And (e.Shift Or e.Control)) And e.KeyCode = Keys.D) Then
' do something
End If

Or

If ((e.Alt And e.Shift) And e.KeyCode = Keys.D) OrElse _
((e.Alt And e.Control) And e.KeyCode = Keys.D) Then
' do something
End If
hope that helps..
Imran.

"OpticTygre" <op********@adelphia.net> wrote in message
news:Dt********************@adelphia.com...
Sortof. The problem is that I'm trying to catch when the ALT and the SHIFT or CONTROL key is pressed along with the 'D' key. So something like:

If e.Modifiers = Keys.Alt And (e.modifiers = keys.shift or e.modifiers =
keys.control) And e.KeyCode = keys.D Then do something

The problem is, that code doesn't catch the keys properly.

-Jason

"Imran Koradia" <no****@microsoft.com> wrote in message
news:eO**************@TK2MSFTNGP10.phx.gbl...
Debug.WriteLine(e.Modifiers = Keys.Control OrElse e.Modifiers =

Keys.Shift)


'Keys' are bit flags. Use 'Or' to do a bitwise Or. OrElse is a logical
operator not a bitwise operator.

Debug.WriteLine(e.Modifiers = Keys.Control Or e.Modifiers = Keys.Shift)
hope that helps..
Imran.


Nov 21 '05 #7
Ahhhh, yes. Thanks a bunch. It seems that programming it with e.Modifiers
= Keys.control doesn't work properly, but just doing e.control works fine.
Same with the Alt and Shift keys. What a pain. Thanks again.

-Jason

"Imran Koradia" <no****@microsoft.com> wrote in message
news:uR*************@tk2msftngp13.phx.gbl...
try something like this:

If (((e.Alt And (e.Shift Or e.Control)) And e.KeyCode = Keys.D) Then
' do something
End If

Or

If ((e.Alt And e.Shift) And e.KeyCode = Keys.D) OrElse _
((e.Alt And e.Control) And e.KeyCode = Keys.D) Then
' do something
End If
hope that helps..
Imran.

"OpticTygre" <op********@adelphia.net> wrote in message
news:Dt********************@adelphia.com...
Sortof. The problem is that I'm trying to catch when the ALT and the

SHIFT
or CONTROL key is pressed along with the 'D' key. So something like:

If e.Modifiers = Keys.Alt And (e.modifiers = keys.shift or e.modifiers =
keys.control) And e.KeyCode = keys.D Then do something

The problem is, that code doesn't catch the keys properly.

-Jason

"Imran Koradia" <no****@microsoft.com> wrote in message
news:eO**************@TK2MSFTNGP10.phx.gbl...
>> Debug.WriteLine(e.Modifiers = Keys.Control OrElse e.Modifiers =
> Keys.Shift)
>>
>
> 'Keys' are bit flags. Use 'Or' to do a bitwise Or. OrElse is a logical
> operator not a bitwise operator.
>
> Debug.WriteLine(e.Modifiers = Keys.Control Or e.Modifiers = Keys.Shift)
>
>
> hope that helps..
> Imran.
>
>



Nov 21 '05 #8
It goes like this:

If (e.Control) Then Console.WriteLine ("Control key pressed")
If (e.Alt) Then Console.WriteLine ("Alt key pressed")
If (e.Shift) Then Console.WriteLine ("Shift key pressed")

If (e.Modifiers = (Keys.Control Or Keys.Alt)) Then Console.WriteLine
("Ctrl+Alt pressed")

Modifiers property is of bit-flag type.

Hope this helps.

"OpticTygre" <op********@adelphia.net> wrote in message
news:Rf********************@adelphia.com...
Still not working right.

If I do a:

Debug.WriteLine(e.Modifiers = Keys.Control AndAlso e.Modifiers = Keys.Shift)

Then I get a 'false' for the control key, a 'false' for the shift key, and a
'false' for both keys pressed.

If I do a:

Debug.WriteLine(e.Modifiers = Keys.Control OrElse e.Modifiers = Keys.Shift)

Then I get a 'true' for the control key, a 'true' for the shift key, and a
'false' for both keys pressed.

Any ideas?

"Shiva" <sh******@online.excite.com> wrote in message
news:e%****************@TK2MSFTNGP15.phx.gbl...
Hi,

KeyPress event doesn't expose what modifier keys were pressed.

In KeyDown event, use KetEventArgs.Modifiers, KetEventArgs.Control,
KetEventArgs.Shift & KetEventArgs.Alt properties.

HTH

"OpticTygre" <op********@adelphia.net> wrote in message
news:1r********************@adelphia.com...
How would I be able to capture multiple key presses, such as Alt+Shift+D
in
a form's KeyPress and KeyDown events? Thanks in advance.

-Jason


Nov 21 '05 #9
Kindof like how "1 Or'd with 2 = 3" I think I got it. Thanks.
"Shiva" <sh******@online.excite.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
It goes like this:

If (e.Control) Then Console.WriteLine ("Control key pressed")
If (e.Alt) Then Console.WriteLine ("Alt key pressed")
If (e.Shift) Then Console.WriteLine ("Shift key pressed")

If (e.Modifiers = (Keys.Control Or Keys.Alt)) Then Console.WriteLine
("Ctrl+Alt pressed")

Modifiers property is of bit-flag type.

Hope this helps.

"OpticTygre" <op********@adelphia.net> wrote in message
news:Rf********************@adelphia.com...
Still not working right.

If I do a:

Debug.WriteLine(e.Modifiers = Keys.Control AndAlso e.Modifiers =
Keys.Shift)

Then I get a 'false' for the control key, a 'false' for the shift key, and
a
'false' for both keys pressed.

If I do a:

Debug.WriteLine(e.Modifiers = Keys.Control OrElse e.Modifiers =
Keys.Shift)

Then I get a 'true' for the control key, a 'true' for the shift key, and a
'false' for both keys pressed.

Any ideas?

"Shiva" <sh******@online.excite.com> wrote in message
news:e%****************@TK2MSFTNGP15.phx.gbl...
Hi,

KeyPress event doesn't expose what modifier keys were pressed.

In KeyDown event, use KetEventArgs.Modifiers, KetEventArgs.Control,
KetEventArgs.Shift & KetEventArgs.Alt properties.

HTH

"OpticTygre" <op********@adelphia.net> wrote in message
news:1r********************@adelphia.com...
How would I be able to capture multiple key presses, such as Alt+Shift+D
in
a form's KeyPress and KeyDown events? Thanks in advance.

-Jason


Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Steve Jorgensen | last post by:
Well, it seems that Microsoft, or whatever powers that be have decided it's time for us to have yet another standard keyboard layout change. I think I see that the point of this one was to reduce...
5
by: nx-2000 | last post by:
I've got a very large C# forms app and now that its being used in bigger environments we're getting a steady stream of "why does it do this?" problems. The most nagging of which right now is that...
3
by: Billy Porter | last post by:
How would I go about catching events outside my application? Example: Babylon Pro is a program that runs silently (with a hidden GUI) in the system tray. Whenever you use the keyboard/mouse...
5
by: Serdar C. | last post by:
hello everyone, i have a question about retrieving data from a bar code reader plugged in keyboard port (ps/2) i really dont know how to retrieve data from keyboard, i tried some methods but all i...
2
by: Simon Verona | last post by:
I know that Windows has a "clickable" keyboard that can pop up when necessary.. I have a touch-screen based application. Is there anyway that I can utilise this keyboard application in windows...
5
by: lord.zoltar | last post by:
How can I prevent the big close button in the top of the window from closing the window? I want to have and "are you sure?" confirmation so the user must press "Yes" before the program ends. Right...
7
by: Brian Ward | last post by:
Hello ===== I am trying to do a simple exercise using Visual Studio C#. I have a form with one picturebox and some buttons. I want to be able to control a picture box graphic using the keyboard...
10
by: moamin123 | last post by:
hello i am trying to create a keyboard rogram for my college coursework. i had to create the buttons which include all 26 letters of the alphabet and the space, backspace and return buttons. upon...
2
by: petinboy | last post by:
Hi All! I am developing an accessibility keyboard application with Visual Studio 2005 Professional Edition and with C#. The application is a keyboard with buttons that interacts with any...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.