Hotkey - SPACE BAR

I use KeyPreview = True for form

Then have:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeySpace Then
 etc etc

Problem - if i run the program it performs the keydown event ok but also any command button that has the focus at the time - no good

How to simply get the SPACE BAR to perform something on its own ?
clapper100497Asked:
Who is Participating?
 
DrDelphiConnect With a Mentor Commented:
Try this:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 32 Then
   MsgBox "Space key pressed"
   KeyCode = 0
End If



Good luck!!
0
 
clapper100497Author Commented:
KeyCode = 0 did the trick !
Well done and thanks !!!!
0
 
clapper100497Author Commented:
Thanks for such a simple solution
Appreciated !!!
0
 
DrDelphiCommented:
Cheers.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.