so how can it be done ?
Printable View
so how can it be done ?
you will have to set foucs on something and set the code at keypress event
and the keypress event how does it works?
You guys don't seem to be talking about the same thing. Looks like paok is trying to make a calculator, yes?
I want a button on the keyboard eg, the + when pressed to do the same thing with the optical button visual basic
that's all
Dim KeyNumber As Integer
For KeyNumber = 1 To 132
If GetAsyncKeyState(13) < 0 Then
your code for optical button
End If
Next
put this code in timer and set interval to 1 , press enter
Why a timer? Why the GetAsync Key state?
If you want to capture a keypress in VB set the form keypreview=true and use the form keydown or keypress event.
And never set the timer interval to 1
If the timer actually could work that fast then it may try to execute your code 100 times when you press the button
i dont know to use the case select option that why i use this code
and set the form key preview = trueCode:Option Explicit
Dim result As Integer
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim KeyNumber As Integer
For KeyNumber = 1 To 132
If GetAsyncKeyState(vbKeyAdd) < 0 Then
cmdADD_Click
End If
Next
End Sub
and press + key at the numpad
this worked ?
the 0 at the come what does?
not getting u what u saying ?
here the 0 who is the role of itCode:If GetAsyncKeyState(vbKeyAdd) < 0 Then
it means if pressed
Don't use the loop in the key press event. Use select case instead.
You also do not need to use the keyasync stuff
Note: rather than use the ASC() you can look up the ascii codes for the symbols and use the decimal code instead as I have shown for the enter key.Code:Select case KeyAscii
Case asc("+")
'code for whatever you want to do if the key was the + key
Case asc("-" )
'code for when the - key is pressed
Case 13
'when the enter key is pressed
End Select
i have to insert a timer?
There is no need for a timer if you want to capture keys pressed within your application you use the Keypress or Keydown event this is what they are there for.
the next what does?Code:End If
Next
End Sub
it gets me an error hear
put this line at top of code
Code:Option Explicit
Dim result As Integer
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
to the general?