School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,144 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,821 people online right now. Registration is fast and FREE... Join Now!



need to add hotkeys

need to add hotkeys Rate Topic: -----

#1 dimpa3  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 27-February 09


Dream Kudos: 0

Posted 22 April 2009 - 05:14 AM

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
Was This Post Helpful? 0
  • +
  • -


#2 June7  Icon User is offline

  • D.I.C Addict
  • Icon
  • Group: Members w/DIC++
  • Posts: 591
  • Joined: 09-December 08


Dream Kudos: 0

Posted 22 April 2009 - 05:05 PM

Check this URL
http://msdn.microsof...0wa(VS.71).aspx
Was This Post Helpful? 0
  • +
  • -

#3 Zhalix  Icon User is offline

  • D.I.C Regular
  • PipPipPip
  • Group: Members
  • Posts: 260
  • Joined: 07-May 08


Dream Kudos: 0

Posted 22 April 2009 - 05:44 PM

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.
Was This Post Helpful? 0
  • +
  • -

#4 dimpa3  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 27-February 09


Dream Kudos: 0

Posted 23 April 2009 - 07:00 AM

could you explain how to use the keystate api?

ty for helping
Was This Post Helpful? 0
  • +
  • -

#5 June7  Icon User is offline

  • D.I.C Addict
  • Icon
  • Group: Members w/DIC++
  • Posts: 591
  • Joined: 09-December 08


Dream Kudos: 0

Posted 23 April 2009 - 12:22 PM

Found one URL with what appears to be a good example.
http://gpwiki.org/in...GetKeyState_API
Was This Post Helpful? 0
  • +
  • -

#6 firebolt  Icon User is offline

  • D.I.C Lover
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 5,555
  • Joined: 20-February 09


Dream Kudos: 1675

Posted 23 April 2009 - 05:01 PM

Look here:
http://www.youtube.c...h?v=Xr_cwdczOzo

Also test this:
Private Sub Form_Load() 
KeyPreview = True 
End Sub 


Then for the hotkey
If KeyCode = vbKeyF1 then  Command1_Click 


This post has been edited by firebolt: 23 April 2009 - 05:01 PM

Was This Post Helpful? 0
  • +
  • -

#7 dimpa3  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 27-February 09


Dream Kudos: 0

Posted 24 April 2009 - 06:12 AM

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 April 2009 - 06:40 AM

Was This Post Helpful? 0
  • +
  • -

#8 Zhalix  Icon User is offline

  • D.I.C Regular
  • PipPipPip
  • Group: Members
  • Posts: 260
  • Joined: 07-May 08


Dream Kudos: 0

Posted 24 April 2009 - 07:29 AM

There's no reason to give up, it's really very simple.

Put this line in the general declarations:
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.
GetAsyncKeyState KeyCode


Then below that, put this code:

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.
Was This Post Helpful? 0
  • +
  • -

#9 dimpa3  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 27-February 09


Dream Kudos: 0

Posted 24 April 2009 - 07:48 AM

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 April 2009 - 07:52 AM

Was This Post Helpful? 0
  • +
  • -

#10 Nikhil_07n  Icon User is offline

  • Idiot of the year.
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 2,175
  • Joined: 09-January 09


Dream Kudos: 1200

Posted 24 April 2009 - 09:51 AM

Alternatively.......you can try the Keypress event.
Was This Post Helpful? 0
  • +
  • -

#11 Zhalix  Icon User is offline

  • D.I.C Regular
  • PipPipPip
  • Group: Members
  • Posts: 260
  • Joined: 07-May 08


Dream Kudos: 0

Posted 24 April 2009 - 06:19 PM

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.
Was This Post Helpful? 0
  • +
  • -

#12 dimpa3  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 27-February 09


Dream Kudos: 0

Posted 25 April 2009 - 06:42 AM

wel i got it to work thankyou
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month