By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,156 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,156 IT Pros & Developers. It's quick & easy.

vb.NET Keypresses

P: n/a
I am currently trying to teach myself .NET (specifically vb.NET). I have
been working with VBA in Access 97 for a few years now, and consider myself
to be quite proficient.

At present, I have an issue with the concept of detecting keypresses. I use
this frequently in Access 97, generally for giving the user an
keyboard-based alternative to clicking on command buttons.

For example, if I have a form where the user will be entering records, as
well as navigating through them, the user has the choice of either clicking
on the various command buttons for navigation and record saving, or pressing
the PgUp and PgDn keys for forward and backward navigation respectively, as
well as the F2 key to save a record. If the user presses CTRL-PgUp/Dn, they
will be able to move to the first or last record in the recordset.

I want to be able to provide this functionality in vb.NET, but can't seem to
find a way of doing it.

I've attached a sample of the code that I would generally use on an Access
form, which I hope will explain what I mean:

Thanks In Advance
Ian Henderson
Database Developer and .NET novice

Private Sub Form_KeyDown(Keycode As Integer, Shift As Integer)

intShiftDown = (Shift And acShiftMask) > 0
intCtrlDown = (Shift And acCtrlMask) > 0
intAltDown = (Shift And acAltMask) > 0

If intShiftDown Then
intShiftDown = 0
Keycode = 0
Exit Sub
End If

If intAltDown Then
intAltDown = 0
Keycode = 0
Exit Sub
End If

If intCtrlDown Then
Select Case Keycode
Case vbKeyQ
strMsg = "Are you sure you wish to quit the " &
DLookup("ShortName", "DatabaseName") & "?"
StrTitle = "Confirm Action"
IntStyle = vbYesNo + vbDefaultButton2
Response = MsgBox(strMsg, IntStyle, StrTitle)
If Response = vbYes Then DoCmd.Quit acQuitPrompt
Keycode = 0
Exit Sub
Case Else
Keycode = 0
Exit Sub
End Select
intCtrlDown = 0
Keycode = 0
Exit Sub
Else
Select Case Keycode
Case vbKeyW
WorkForms.Visible = True
Keycode = 0
Exit Sub
Case vbKeyL
LookupTables.Visible = True
Keycode = 0
Exit Sub
Case vbKeyR
Reports.Visible = True
Keycode = 0
Exit Sub
Case vbKey1
WorkOnBankAccountsBtn_Click
Keycode = 0
Exit Sub
Case vbKey2
WorkOnTelephoneAccountsBtn_Click
Keycode = 0
Exit Sub
Case Else
Keycode = 0
Exit Sub
End Select
End If

End Sub

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello,

"Ian Henderson" <ho**@ihenderson.co.uk> schrieb:
keyboard-based alternative to clicking on command
buttons. [...] the PgUp and PgDn keys for forward and backward
navigation respectively, as well as the F2 key to save
a record. If the user presses CTRL-PgUp/Dn, they
will be able to move to the first or last record in the recordset.

I want to be able to provide this functionality in vb.NET, but can't seem to find a way of doing it.


Add a hidden menu and define the shortcuts in the 'MenuItem's'
'Shortcut' property. Then you can add the code to the menu item's
'Click' event handler.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2

P: n/a
Ok, thanks for that.

Having answered that for me, can you tell me how I set the shortcut up to be
the PgUp key, or a combination of SHIFT and PgUp?

Ian

"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:eg*************@TK2MSFTNGP11.phx.gbl...
Hello,

"Ian Henderson" <ho**@ihenderson.co.uk> schrieb:
keyboard-based alternative to clicking on command
buttons.

[...]
the PgUp and PgDn keys for forward and backward
navigation respectively, as well as the F2 key to save
a record. If the user presses CTRL-PgUp/Dn, they
will be able to move to the first or last record in the recordset.

I want to be able to provide this functionality in vb.NET, but can't

seem to
find a way of doing it.


Add a hidden menu and define the shortcuts in the 'MenuItem's'
'Shortcut' property. Then you can add the code to the menu item's
'Click' event handler.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.