ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Please help: Interrupt routine to get input from key (https://www.excelbanter.com/excel-programming/438660-please-help-interrupt-routine-get-input-key.html)

bau

Please help: Interrupt routine to get input from key
 
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

joel[_584_]

Please help: Interrupt routine to get input from key
 

there is a key press event. Below is the code from the VBA help topic
for key press event.


Private Sub TextBox1_KeyPress(ByVal KeyAscii As _
MSForms.ReturnInteger)
TextBox2.Text = TextBox2.Text & Chr(KeyAscii)

'To handle keyboard combinations (using SHIFT,
'CONTROL, OPTION, COMMAND, and another key),
'or TAB or ENTER, use the KeyDown or KeyUp event.
End Sub

Private Sub UserForm_Initialize()
Move 0, 0, 570, 380

TextBox1.Move 30, 40, 220, 160
TextBox1.MultiLine = True
TextBox1.WordWrap = True
TextBox1.Text = "Type text here."
TextBox1.EnterKeyBehavior = True


TextBox2.Move 298, 40, 220, 160
TextBox2.MultiLine = True
TextBox2.WordWrap = True
TextBox2.Text = "Typed text copied here."
TextBox2.Locked = True
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=171938

Microsoft Office Help


Chip Pearson

Please help: Interrupt routine to get input from key
 

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]




On Wed, 20 Jan 2010 14:44:02 -0800, bau
wrote:

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


bau

Please help: Interrupt routine to get input from key
 
Thank you very much. It works perfectly!

"Chip Pearson" wrote:


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]




On Wed, 20 Jan 2010 14:44:02 -0800, bau
wrote:

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

.


bau

Please help: Interrupt routine to get input from key
 
Thank you very much. It works well.
Regards,
Bau

"Chip Pearson" wrote:


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]




On Wed, 20 Jan 2010 14:44:02 -0800, bau
wrote:

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

.



All times are GMT +1. The time now is 05:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com