
"HELP! VB2008 keypress help" Topic
5 Posts
All members in good standing are free to post here. Opinions expressed here are solely those of the posters, and have not been cleared with nor are they endorsed by The Miniatures Page.
Please be courteous toward your fellow TMP members.
For more information, see the TMP FAQ.
Back to the Computer Stuff Plus Board
Areas of InterestGeneral
Featured Hobby News Article
Featured Link
Featured Ruleset
Featured Showcase Article Is there finally a gluestick worth buying for paper modelers?
Featured Workbench Article Can a plastic flower become a wargaming shrub? Or maybe a small tree?
Featured Profile Article Time to replace the equipment again!
|
| Last Hussar | 26 Aug 2008 3:52 p.m. PST |
I want to detect which key has been pressed in VB2008. Unfortunately MS have got rid of the simple Private Sub Form_KeyPress(keyascii As Integer) method of VB6. Does anyone know how? What does the key press return (ascii or 'key symbol')? Thanks NB Please no rants re VB etc- I'm self teaching what I have, can't justify spending money on buying another language. |
| SpaceCudet | 27 Aug 2008 4:24 a.m. PST |
IT still has the keypress: Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress and you use e.KeyChar You may find KeyDown or KeyUp better which returns a KeyCode and is better for tracking special keys: Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown You need to send the Keypreview property of the form to true. Note: this is assuming you are using WinForms and not WPF. |
| Last Hussar | 27 Aug 2008 9:48 a.m. PST |
Thanks. Off the back of your answer I've Googled e.keychar, and found the MS page on their help site- I tried using search yesterday, and failed. I may come back with a question on actual coding though. ie- with in the Private sub, go I put Label1.Text=ekeychar to show key pressed (haven't got access to VB at the moment). |
| SpaceCudet | 27 Aug 2008 10:10 a.m. PST |
ie- with in the Private sub, do I put Label1.Text=e.keychar to show key pressed (haven't got access to VB at the moment). Yes. |
| Last Hussar | 27 Aug 2008 3:50 p.m. PST |
I've got it working- it was the keypreview that was the bit I kept missing. I now have a program that responds to both number row and numberpad, as well as on screen buttons Thanks SpaceCudet |
|