473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

vb.NET Keypresses

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
2 8213
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: junglist | last post by:
Hi, i have created a Pong game Application where two players control their pads using the keyboard. the problem is that one player is using the action keys VK_UP and VK_DOWN in keyPressed() and...
7
by: kstahl | last post by:
Howdy, I would like to get down to the nitty-gritty of the keyboard's operation. Specifically, I would like to poll only a few keys on the keyboard, and I would like to know when more than one...
1
by: dthom | last post by:
Hi, I have a Win CE 4.2.NET device, where i need to send F11 - but there is only 4 functionkeys on this device, therefore i want to promote F4 to become F11. In a normal Windows application i...
9
by: robert_rowe | last post by:
Does anyone know how to detect keypresses in a Datagrid cell? The Keypress event ofthe datagrid doesn't fire if you are in a cell. Neither does KeyUp & KeyDown. I've tried hooking in to the...
2
by: Matt | last post by:
Hi all, I have written a small application that runs from the system tray. I need to be able to identify when a user has pressed certain key combinations in any aplication and then respond to...
5
by: Robert W. | last post by:
I'm trying to setup a mechanism whereby I store a formatting code in the Tag of a textbox. This code might be "UpperCase" or "LowerCase" or "NumericOnly". I've been trying out various code in...
1
by: TheRain | last post by:
I'm working on a .NET C++ project. The program loads and creates a tray icon, but is not visible on the screen. So what I'm looking for is a way to detect when a specific key combination is...
1
by: mflll | last post by:
I am having trouble responding writing a Javascript Program respond to keypresses on top of a paragraph. Here is the code I tried: <HTML> <SCRIPT Language="JavaScript">...
1
by: Sparky74 | last post by:
Hi. There are so many help offerings out there for the detection of keypresses. I would like to know what the "correct way" is to intercept a keypress for a control. I have overidden the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.