capture keyboard events without interfering with apps 
Author Message
 capture keyboard events without interfering with apps

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



Thu, 22 Sep 2005 13:21:36 GMT  
 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



Thu, 22 Sep 2005 23:50:15 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Capturing Mouse & Keyboard Events Anywhere in Application

2. Capturing Keyboard Event

3. Capturing Mouse & Keyboard Events Anywhere in Application

4. Capture desktop keyboard events?

5. How do I capture mouse and keyboard events?

6. Capturing Mouse/Keyboard Events at the Application Level

7. capture all keyboard events

8. Capture Keyboard Event

9. Capturing Mouse & Keyboard Events Anywhere in Application

10. capturing mouse and keyboard events

11. Capture a mouse click without mousedown events

12. Capturing all keystrokes, without app focus?

 

 
Powered by phpBB® Forum Software