Please help: Interrupt routine to get input from key

B

bau

I want to create a loop so the program will look for the actual keyboard
input (not a program sendkey nor the virtual key) , say "arrow_down" key, and
when it sees the change, it does something else.

Here is my loop:

Dim keystat(0 To 255) As Byte

While keystat(40) <> 1 ' keystat(40) is arrow down key

' Check if the arrow down key has been pressed
' This is where I could not see the change. Need some interrupt loop to
' enter keyboard such as input (but I don't want to see it shows on the
screen)

retval = GetKeyboardState(keystat(0))

Wend

Thanks,
Bau
 
C

Chip Pearson

Use GetAsyncKeyState instead of GetKeyboardState and toss in a
DoEvents at the top of the loop. E.g,

Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As
Long) As Integer

Sub AAA()
Dim B(0 To 255) As Byte
Dim N As Integer
Do Until False
DoEvents
N = GetAsyncKeyState(vbKeyDown)
If N = 0 Then
Range("A1").Value = "up"
Else
Range("A1").Value = "down"
End If
Loop
End Sub

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]
 
B

bau

Thank you very much. It works perfectly!

Chip Pearson said:
Use GetAsyncKeyState instead of GetKeyboardState and toss in a
DoEvents at the top of the loop. E.g,

Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As
Long) As Integer

Sub AAA()
Dim B(0 To 255) As Byte
Dim N As Integer
Do Until False
DoEvents
N = GetAsyncKeyState(vbKeyDown)
If N = 0 Then
Range("A1").Value = "up"
Else
Range("A1").Value = "down"
End If
Loop
End Sub

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




I want to create a loop so the program will look for the actual keyboard
input (not a program sendkey nor the virtual key) , say "arrow_down" key, and
when it sees the change, it does something else.

Here is my loop:

Dim keystat(0 To 255) As Byte

While keystat(40) <> 1 ' keystat(40) is arrow down key

' Check if the arrow down key has been pressed
' This is where I could not see the change. Need some interrupt loop to
' enter keyboard such as input (but I don't want to see it shows on the
screen)

retval = GetKeyboardState(keystat(0))

Wend

Thanks,
Bau
.
 
B

bau

Thank you very much. It works well.
Regards,
Bau

Chip Pearson said:
Use GetAsyncKeyState instead of GetKeyboardState and toss in a
DoEvents at the top of the loop. E.g,

Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As
Long) As Integer

Sub AAA()
Dim B(0 To 255) As Byte
Dim N As Integer
Do Until False
DoEvents
N = GetAsyncKeyState(vbKeyDown)
If N = 0 Then
Range("A1").Value = "up"
Else
Range("A1").Value = "down"
End If
Loop
End Sub

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




I want to create a loop so the program will look for the actual keyboard
input (not a program sendkey nor the virtual key) , say "arrow_down" key, and
when it sees the change, it does something else.

Here is my loop:

Dim keystat(0 To 255) As Byte

While keystat(40) <> 1 ' keystat(40) is arrow down key

' Check if the arrow down key has been pressed
' This is where I could not see the change. Need some interrupt loop to
' enter keyboard such as input (but I don't want to see it shows on the
screen)

retval = GetKeyboardState(keystat(0))

Wend

Thanks,
Bau
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top