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

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




help with my project please

 
Reply to this topicStart new topic

help with my project please

itso2005
30 Jun, 2008 - 04:39 PM
Post #1

New D.I.C Head
*

Joined: 30 Jun, 2008
Posts: 3

Hey i am using VB 2008 and i am conducting a macro program. My program has two buttons a start and a stop button. I want to make it so when my form loads I can use two separate keyboard keys as shortcuts 1 to execute the start button and 1 to execute the stop button does some1 have an idea please?
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Help With My Project Please
30 Jun, 2008 - 06:15 PM
Post #2

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,164



Thanked: 32 times
Dream Kudos: 1625
My Contributions
First of all, this is a vb.net question, so it should of been posted in that forum (a mod will move it shortly). Also, i do know the answer to your question. What you want is to create a KeyDown() event for your form. This is the code you want:

vb

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
'your code goes here
End Sub

That sub will fire every time a key is pressed and the form has focus. To get what key was pressed, type

vb

e.KeyCode

that will return the key that was pressed. Also, there are three other boolean (true/false) values that will return weather or Shift, Alt, or Ctrl was held down. There values are called

vb

e.Shift
e.Alt
e.Control

To use this to do what you want, here is an example. If you had a button called Button1, and if 'Ctrl+A' was your hotkey, this is what you would do

vb

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.Control And e.KeyCode = Keys.A Then
Button1.PerformClick()
End If
End Sub

Hope that helps
User is online!Profile CardPM
+Quote Post

itso2005
RE: Help With My Project Please
30 Jun, 2008 - 07:40 PM
Post #3

New D.I.C Head
*

Joined: 30 Jun, 2008
Posts: 3

thanx bro that worked great...and sry for posting at wrong place
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Help With My Project Please
30 Jun, 2008 - 07:56 PM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to VB.NET smile.gif

Good answer jacobjordan icon_up.gif
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 06:45PM

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