By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,312 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

Catching Keyboard buttons (multiple)

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
> 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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.