Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,278 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,257 people online right now. Registration is fast and FREE... Join Now!




Problem with keycode Alt

2 Pages V  1 2 >  
Reply to this topicStart new topic

Problem with keycode Alt

Mangore
11 Oct, 2008 - 09:18 AM
Post #1

D.I.C Head
**

Joined: 11 Oct, 2008
Posts: 80

I'm tried this code to show message when I press on the delete button and it succeed with me. I wnat to do same thing with Alt button but it didn't succeed with me
Can you help.
CODE
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Delete Then
            MsgBox("ok")
        End If
    End Sub



This post has been edited by Mangore: 11 Oct, 2008 - 09:19 AM
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Problem With Keycode Alt
11 Oct, 2008 - 09:30 AM
Post #2

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
Simple. Unlike the delete key, there is no key code member for alt, control, or shift. To see if the alt key is held down, simply use:
vb

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Alt Then
MsgBox("ok")
End If
End Sub

The e.Alt property returns a boolean of whether or not the alt key is held down.
User is offlineProfile CardPM
+Quote Post

Mangore
RE: Problem With Keycode Alt
11 Oct, 2008 - 10:38 AM
Post #3

D.I.C Head
**

Joined: 11 Oct, 2008
Posts: 80

How to join tow buttons
exa: press alt+ctrl

This post has been edited by Mangore: 11 Oct, 2008 - 10:41 AM
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Problem With Keycode Alt
11 Oct, 2008 - 11:05 AM
Post #4

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
Just add an and operator to the if statement:
vb

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Alt And e.Control Then
MsgBox("ok")
End If
End Sub

User is offlineProfile CardPM
+Quote Post

Mangore
RE: Problem With Keycode Alt
11 Oct, 2008 - 12:00 PM
Post #5

D.I.C Head
**

Joined: 11 Oct, 2008
Posts: 80

Its wonderfull
What if I want the vb do inversely?
It's mean in the previews code wills does something if we implement the press keys
so I want a code to implement the press keys instead of the user.

example:
CODE
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
' implement instead of users
e.Alt And e.Control
End S
ub

And thank you for help!




User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Problem With Keycode Alt
11 Oct, 2008 - 12:12 PM
Post #6

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
That's a bit more complicated. You will need to use a declare on the User32 dll, however i forgot what it was. I will try to find the function you need to use.
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Problem With Keycode Alt
11 Oct, 2008 - 01:32 PM
Post #7

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
Here is a thread i started a while ago when i was wondering how to do the same thing. I hope it can be of help to you.
User is offlineProfile CardPM
+Quote Post

gbertoli3
RE: Problem With Keycode Alt
11 Oct, 2008 - 02:48 PM
Post #8

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
What about using the SendKeys
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Problem With Keycode Alt
11 Oct, 2008 - 02:57 PM
Post #9

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
QUOTE(gbertoli3 @ 11 Oct, 2008 - 05:48 PM) *

What about using the SendKeys

As PsychoCoder's coding religion would say, SendKeys is a legacy function left over from the old VB days. You can use it if you like, but it's not really recommended.
User is offlineProfile CardPM
+Quote Post

gbertoli3
RE: Problem With Keycode Alt
11 Oct, 2008 - 03:03 PM
Post #10

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
I agree, but thought Mangore might think it would be easier.
User is offlineProfile CardPM
+Quote Post

Mangore
RE: Problem With Keycode Alt
11 Oct, 2008 - 03:16 PM
Post #11

D.I.C Head
**

Joined: 11 Oct, 2008
Posts: 80

I'm sorry. for I'm newbie, I don't know how to use this in my project.
Thank you foru your effort

User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Problem With Keycode Alt
11 Oct, 2008 - 03:22 PM
Post #12

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
Because you are a newbie, i recommend using the SendKeys function. In VB.NET, i believe it is already imported, so all you have to do is type "SendKeys". Try it.
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 05:19AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month