Skywalker Posted June 5, 2003 Posted June 5, 2003 i want to press the escape button so that the message box comes up, that doesn't work. When i fill in the number for escape and i press then on button 1 on the keyboard, it works perfect? What has to be changed? Public Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress If e.KeyChar = "ESC" Then MsgBox("blabla", , "Product information") End If End Sub Quote
*Experts* mutant Posted June 5, 2003 *Experts* Posted June 5, 2003 Use this: If e.KeyCode = Keys.Escape Then Quote
Skywalker Posted June 6, 2003 Author Posted June 6, 2003 It still doesn't work, now it gives an error on Handles button1, because that isn't in the System.Windows.Forms.Keys. Public Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.Keys) Handles Button1.KeyPress ' <-------- If e.KeyCode = Keys.Escape Then MsgBox("blabla", , "Product information") End If End Sub Quote
Administrators PlausiblyDamp Posted June 6, 2003 Administrators Posted June 6, 2003 The KeyPress anly gives you the Key's character not hte underlying code. However if you use either the KeyUp or KeyDown events then the above code should work just fine. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
aewarnick Posted June 6, 2003 Posted June 6, 2003 Key press is mainly used for rapid fire keys. Keys that you hold in to get repeating characters. I always use KeyUp or KeyDown for most things. Quote C#
Leaders dynamic_sysop Posted June 10, 2003 Leaders Posted June 10, 2003 erm that form1_kepress looks a bit hey wire :-\ is it supposed to say handles button1.keypress when it's a form keypress event ? Public Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.Keys) Handles Button1.KeyPress the correct format for form keypress is this ... Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress End Sub Quote
sizer Posted June 10, 2003 Posted June 10, 2003 ProcesCmdKey try with this code :: Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean If keyData = Keys.Escape Then MessageBox.Show("blah") End If If keyData = Keys.A Then MessageBox.Show("A") End If return true End Function :D Quote Some people are wise and some are other-wise.
ThePentiumGuy Posted June 10, 2003 Posted June 10, 2003 hmm look at the code u pasted above, it still says button1.keypress if u have 'button1' on the form, then use Button1.keyup, but if u dont have a button on the form use form1.keyup, the reason is, when u have a button, the button has focus, so the Form1.keyup event wont work.. select Button1 and KeyUp and type Private Sub Button1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress If e.keycode = keys.escape then 'blah End If End Sub Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Moishe Posted June 24, 2003 Posted June 24, 2003 KeyCode Hi, I'm using VB.Net the vbKeyF5 code is &H74 and it givese me invalid synax error If e.vbKeyF5 = Keys.F5 Then blah end if Thanks for any help Quote
ThePentiumGuy Posted June 24, 2003 Posted June 24, 2003 um just use if e.keycode = keys.f5 or somethign Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Moishe Posted June 24, 2003 Posted June 24, 2003 KeyCode is not a member of a system.windows.forms.keypresseventargs Quote
*Experts* Volte Posted June 24, 2003 *Experts* Posted June 24, 2003 You need to do it like this:If e.KeyChar = Convert.ToChar(Keys.F5) Thenit's KeyChar not KeyCode, and you need to convert the Keys object to a char first. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.