Using Keyboard Input in VB

Intel / D975xbx2
December 4, 2009 at 20:54:26
Specs: Microsoft Windows Vista x64, Intel Q6600 / 6GB DDR2
I'm playing around with Visual Basic for the first time in a while and
am having trouble figuring something out. I'm making a calculator
program to sort of work out the rust, so to speak, and I want to have
it so when you, for example, press the 9 key on the keyboard it's
the same as if I pressed the 9 button on the form. I'm having
difficulty figuring out how to do this.

If someone could aid me in this it would be much appreciated.
Please provide an example, if possible.

Thanks,
Kreeos


See More: Using Keyboard Input in VB

Report •


#1
December 4, 2009 at 21:35:37
Private Sub Form_KeyPress(a As Integer)
Debug.Print "keypress: "; a; " "; Chr(a);" ";str(a)
'basically just put whatever code for processing keys into this 'sub
'fold upper to lower
ch=ucase(chr(a))
b = Str(a)
if b => "0" and b < = "9" then
'call the same routine the form-click calls for entering
'numbers to the form. no need to duplicate it here
'call click_something
end if

use "view code", select "form" and scroll for "keypress"


Report •

#2
December 5, 2009 at 05:58:29
Your code will be dependent on the version of VB you're using. nbrane's code is for VB6, I believe.

Report •

#3
December 5, 2009 at 11:04:27
yes, sorry, i keep forgetting my tools are old... don't have vb.net yet.

Report •

Related Solutions

#4
December 6, 2009 at 07:28:54
I'm using Visual Basic 2008 Express Edition.

Report •

#5
December 6, 2009 at 09:56:22

Report •


Ask Question