|
-
Dec 6th, 2008, 06:15 PM
#1
Thread Starter
Frenzied Member
Capture ALT+X
Hey I need to have an Exit button including keyboard shortcut Alt+X to go to Form 2. But this doesnt work. Any help?
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (Chr(13) + Chr(88)) Then
Me.Hide()
Dim fr2 As New Form2
fr2.Show()
End If
End Sub
Last edited by angelica; Dec 6th, 2008 at 06:35 PM.
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Dec 6th, 2008, 06:36 PM
#2
Re: Capture ALT+X
try this:
vb Code:
Public Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Integer) As Integer
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If GetAsyncKeyState(17) And e.KeyCode = Keys.X Or GetAsyncKeyState(18) And e.KeyCode = Keys.X Then
MsgBox("ALT+X pressed")
End If
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 6th, 2008, 06:39 PM
#3
Re: Capture ALT+X
forgot to mention, you need to set your form .keypreview property to true
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 6th, 2008, 06:56 PM
#4
Re: Capture ALT+X
actually i just found a better way without the api function:
vb Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Modifiers = Keys.Alt And e.KeyCode = Keys.X Then
MsgBox("ALT+X pressed")
End If
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 6th, 2008, 07:09 PM
#5
Thread Starter
Frenzied Member
Re: Capture ALT+X
Hi .paul,
Works fine. Can you please explain to me this bit and what is actually triggers?
Code:
Public Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Integer) As Integer
thanks
Is there a simpler way of doing it because this was an exercise for a very very beginner's exercise to young students!
Last edited by angelica; Dec 6th, 2008 at 07:15 PM.
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Dec 6th, 2008, 08:33 PM
#6
Re: Capture ALT+X
sorry, i made a mistake earlier. i wasn't concentrating.
if you have a button with the text "Exit", change it to "E&xit", then alt+x is your buttons shortcut.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|