Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding HotKeys to a program 2

Status
Not open for further replies.

Aristarco

Programmer
Jun 19, 2000
77
MX
I'm working on a program that uses some navigation buttons and they work fine but, I'd like to assign them hot keys like Ctrl-RightArrow to go forward, Ctrl-Home to go tothe very beginning, etc. I´ve assigned <FONT FACE=monospace>KeyPreview</font> to true in Form_Load. Then I use the <FONT FACE=monospace>KeyDown</font> event to get Shift and KeyCode but not to avail. What am I doing wrong?
 
This should work for you:<br><br><FONT FACE=monospace><br>Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)<br>Dim ShiftDown, AltDown, CtrlDown, Txt<br>ShiftDown = (Shift And vbShiftMask) &gt; 0<br>AltDown = (Shift And vbAltMask) &gt; 0<br>CtrlDown = (Shift And vbCtrlMask) &gt; 0<br><br>If CtrlDown Then<br>&nbsp;&nbsp;&nbsp;&nbsp;Select Case KeyCode<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case vbKeyRight<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Ctrl+RightArrow pressed.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case vbKeyHome<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Ctrl+Home pressed&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;End Select<br>End If<br><br>End Sub<br></font><br><br>Have a nice day.<br> <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top