ex :

while asp web project is running , i have an option for the user , if the user presses F8 key in index page he will be redirected to login page

In the same way while vb application is running i should be able to capture the key press event and redirect the user to certain form

Here user refrers to adminstrator .

Is there an option like that in visual basic

Dani AI

Generated

Two situations need different answers: 1) you want to catch F8 while your VB app has focus, and 2) you want a system-wide hotkey that works while your app runs in the background. The existing replies point in useful directions, but note a key detail: function keys (F1–F12) are non‑printable keys and will not appear in a KeyPress/TextBox KeyPress handler. Use form-level KeyDown/KeyUp and set the form to receive keyboard events before controls instead.

As and showed how to read KeyPress, here is the correct form-level approach in VB.NET (works the same idea in VB6 with Form_KeyDown and KeyPreview):

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
End Sub

Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.F8 Then
' check admin status here, then show login/admin form
Dim frm As New AdminForm()
frm.Show()
End If
End Sub

If the app must respond while it is not the active window, register a global hotkey with the Win32 API (RegisterHotKey) and handle WM_HOTKEY in your window procedure. Register a unique id, call UnregisterHotKey on close, and always check that the current user/session is authorized before opening an admin form. Global hooks (SetWindowsHookEx) are more invasive and may trigger antivirus warnings; prefer RegisterHotKey when possible. Finally, do not rely on a hotkey alone for security — gate admin actions by proper authentication/authorization.

Recommended Answers

All 3 Replies

Try using SendKeys Method

Hi, Use Key_Press event in VB6 to capture the keypress within vb application.

make a form with a textbox (txttext)
and a label (lblkeycode)

Private Sub txtText_KeyPress(KeyAscii As Integer)
    Me.lblKeyCode.Caption = KeyAscii%
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.