VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

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




need to add hotkeys

 

need to add hotkeys

dimpa3

22 Apr, 2009 - 05:14 AM
Post #1

New D.I.C Head
*

Joined: 27 Feb, 2009
Posts: 11

ok so i am making something wich will require a hotkey to make it easier
but i have no idea how to do it :s

so could someone please help me


and as i dont know how to do this i also dont have any code for the hotkeys


User is offlineProfile CardPM
+Quote Post


June7

RE: Need To Add Hotkeys

22 Apr, 2009 - 05:05 PM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 485



Thanked: 38 times
My Contributions
Check this URL
http://msdn.microsoft.com/en-us/library/da5kh0wa(VS.71).aspx
User is offlineProfile CardPM
+Quote Post

Zhalix

RE: Need To Add Hotkeys

22 Apr, 2009 - 05:44 PM
Post #3

D.I.C Regular
***

Joined: 7 May, 2008
Posts: 259



Thanked: 19 times
My Contributions
Well, you can use API to make hotkeys. There's an API specifically for global hotkeys, but I find it harder to use than the getkeystate API checking every few milliseconds for the button press.
User is offlineProfile CardPM
+Quote Post

dimpa3

RE: Need To Add Hotkeys

23 Apr, 2009 - 07:00 AM
Post #4

New D.I.C Head
*

Joined: 27 Feb, 2009
Posts: 11

could you explain how to use the keystate api?

ty for helping
User is offlineProfile CardPM
+Quote Post

June7

RE: Need To Add Hotkeys

23 Apr, 2009 - 12:22 PM
Post #5

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 485



Thanked: 38 times
My Contributions
Found one URL with what appears to be a good example.
http://gpwiki.org/index.php/VB:Tutorials:W...GetKeyState_API
User is offlineProfile CardPM
+Quote Post

firebolt

RE: Need To Add Hotkeys

23 Apr, 2009 - 05:01 PM
Post #6

D.I.C Lover
Group Icon

Joined: 20 Feb, 2009
Posts: 5,475



Thanked: 77 times
Dream Kudos: 1675
My Contributions
Look here:
http://www.youtube.com/watch?v=Xr_cwdczOzo

Also test this:
vb

Private Sub Form_Load()
KeyPreview = True
End Sub

Then for the hotkey
vb

If KeyCode = vbKeyF1 then Command1_Click


This post has been edited by firebolt: 23 Apr, 2009 - 05:01 PM
User is online!Profile CardPM
+Quote Post

dimpa3

RE: Need To Add Hotkeys

24 Apr, 2009 - 06:12 AM
Post #7

New D.I.C Head
*

Joined: 27 Feb, 2009
Posts: 11

ok i tryd the youtube tut but it says
sub or fucntion not defind when i test it

think i will give up on a hotkey for my program

This post has been edited by dimpa3: 24 Apr, 2009 - 06:40 AM
User is offlineProfile CardPM
+Quote Post

Zhalix

RE: Need To Add Hotkeys

24 Apr, 2009 - 07:29 AM
Post #8

D.I.C Regular
***

Joined: 7 May, 2008
Posts: 259



Thanked: 19 times
My Contributions
There's no reason to give up, it's really very simple.

Put this line in the general declarations:
vb
Private Declare Function GetAsyncKeyState Lib "User32" (ByVal vKey As Long) As Integer


Make a timer and make it's interval one millisecond, and in the timer put this code:

This first line is just used to refresh the API. If you don't put this line you will experience problems with the hotkey.
vb
GetAsyncKeyState KeyCode


Then below that, put this code:

vb
If GetAsyncKeyState(KeyCode) Then
'HotKey pressed, put your code here
End If



And that will work. But this code isn't perfect. The hotkey will be detected over and over and execute the code over and over, something you probably don't want to happen. So, put in some extra code to check if the key has been released or not, and if it hasn't, don't execute the code.
User is offlineProfile CardPM
+Quote Post

dimpa3

RE: Need To Add Hotkeys

24 Apr, 2009 - 07:48 AM
Post #9

New D.I.C Head
*

Joined: 27 Feb, 2009
Posts: 11

ok i will try that

edit: yay it works thank you so much

now i am gonne make it work when the key is relaesed
but its not neccesary
its just a simple smal program

This post has been edited by dimpa3: 24 Apr, 2009 - 07:52 AM
User is offlineProfile CardPM
+Quote Post

Nikhil_07n

RE: Need To Add Hotkeys

24 Apr, 2009 - 09:51 AM
Post #10

Idiot of the year.
Group Icon

Joined: 9 Jan, 2009
Posts: 2,129



Thanked: 15 times
Dream Kudos: 1200
My Contributions
Alternatively.......you can try the Keypress event.
User is offlineProfile CardPM
+Quote Post

Zhalix

RE: Need To Add Hotkeys

24 Apr, 2009 - 06:19 PM
Post #11

D.I.C Regular
***

Joined: 7 May, 2008
Posts: 259



Thanked: 19 times
My Contributions
Considering the rate at which people don't follow up to their questions, I decided not to risk it not being solved and went straight for what he was probably asking for.
User is offlineProfile CardPM
+Quote Post

dimpa3

RE: Need To Add Hotkeys

25 Apr, 2009 - 06:42 AM
Post #12

New D.I.C Head
*

Joined: 27 Feb, 2009
Posts: 11

wel i got it to work thankyou


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 10:03PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month