Computer Science Canada Need help with Keypress |
Author: | zwnage [ Sat Jan 20, 2007 12:28 am ] |
Post subject: | Need help with Keypress |
I'm pretty new to visual basic, and for some reason, I cannot get keyboard inputs to work. I want to know when the left or right arrow keys are pressed. It is to replace my joystick so that I can test my program at home. Can anyone help? Thanks for your time. EDIT: I got the inputs to work, but only when there isn't a textbox on the form. Where there is one, I'm writing into the textbox instead of regestering the keypresses like I want them to. |
Author: | cool dude [ Sat Jan 20, 2007 11:04 am ] |
Post subject: | Re: Need help with Keypress |
Can you please be a little more specific. You say that your registering the key presses into the text box instead of how you want it. But how do you want it? What exactly are you trying to do? P.S. Dan the times are screwed up because he posted at 12:28 and i'm posting at 11:04 how is that possible? I guess its something to do with time differences. |
Author: | zwnage [ Sat Jan 20, 2007 2:52 pm ] | ||
Post subject: | Re: Need help with Keypress | ||
I'll give an example: Here's a code I copied from an earlier post, with a few very small changes:
It uses a timer, a form, and a label. When I press a arrow key, it moves the label. Now if I add a textbox to the form, instead of moving the label when I press the arrow keys, it moves the curser in the text box. How would I fix that? |
Author: | Monstrosity_ [ Sat Jan 20, 2007 3:05 pm ] |
Post subject: | Re: Need help with Keypress |
zwnage @ Sat Jan 20, 2007 1:28 am wrote: I got the inputs to work, but only when there isn't a textbox on the form. Where there is one, I'm writing into the textbox instead of regestering the keypresses like I want them to.
Change the forms 'KeyPreview' to True.. Its been a while, but this should pass key events from the forms controls to the form. |
Author: | cool dude [ Sat Jan 20, 2007 3:47 pm ] |
Post subject: | Re: Need help with Keypress |
yes that is exactly right. Another way would be to disable the textbox on your form but if you have it there i'm assuming that you don't won't to disable it. |
Author: | zwnage [ Sat Jan 20, 2007 4:24 pm ] |
Post subject: | RE:Need help with Keypress |
Thanks for the help, the keypreview thing worked! |
Author: | MIdas0036 [ Tue Dec 11, 2007 4:41 pm ] |
Post subject: | RE:Need help with Keypress |
What about using ascii code for the key press function |
Author: | Silent Avenger [ Tue Dec 11, 2007 5:11 pm ] |
Post subject: | Re: RE:Need help with Keypress |
MIdas0036 @ Tue Dec 11, 2007 4:41 pm wrote: What about using ascii code for the key press function
I think ascii code is the easiest way to detect when a key is pressed especially if you're new to VB. |