
capture keyboard events without interfering with apps
You need to use the GetAsyncKeyState API call.
Create a windows form and add a text box and a timer to it. Enable the timer and set its interval to, say, 50. Put the code below (watch for word wrap) in your form's code. Then any keyboard input you type will show up in the text box. Well, almost. This doesn't account for the shift key being down, or keys like control or enter. Read about GetAsyncKeyState to get that--do an unfiltered search for it in VB.net
Private Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Long) As Integer
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" _
(ByVal intChar As Integer) As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim i As Integer
For i = 32 To 255
If OddCheck(GetAsyncKeyState(VkKeyScan(i))) Then Me.TextBox1.Text = Me.TextBox1.Text & Chr(i)
Next
End Sub
Private Function OddCheck(ByVal x As Integer) As Boolean
If x / 2 - Int(x / 2) > 0.000001 Then Return True ' odd integer
End Function
Hello,
How do I capture a word without wrecking the app that has focus? I want the focus to look like it stayed in the originating app.
i.e.:
WORD user types: city
Then in the MyApp a message displays like:Press F8 to Substitute - Omaha
Later I want to be able to hit a F1->12 key and have it run a program or substitute the word for a longer word
I already know about active words
Thanks