|
-
Sep 6th, 2000, 01:19 PM
#1
Thread Starter
Hyperactive Member
my program runs always on top but doesnt have focus. when the user types a keystroke the program needs to intercept what was typed and replace the letter with something else.
Example: user hits the "a" key.
program sees "a" key has been hit.
program adds one to the ASCII value of "a" (which makes it "b")
program displays the letter "b"
the process is invisible to the user. when the hit the "a" key, a "b" appears (just as if the user had hit "b" in the beginning.
also please remember my program does this even if it doesnt have the focus.
thanks for your help!
-
Sep 6th, 2000, 02:18 PM
#2
Try this:
Code:
Private Declare Function GetAsyncKeyState _
Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyA) Then Text1.text = "b"
End Sub
-
Sep 6th, 2000, 02:25 PM
#3
Thread Starter
Hyperactive Member
close...
i tried the code and it is working but the is a problem with using a timer. if i set the interval something slow and you type at a moderate speed, the program only picks up one of keys you press every interval. if you set the interval very fast it sometimes detects 1 key press as to or 3 (because you hold the key in for a split second every time you hit it.)
is there some way to detect the key press without the timer?
thanks for your suggestion. i'd appreciate any more you have.
-
Sep 6th, 2000, 02:53 PM
#4
Set the Timer's interval at 10. Hopefully, that will help.
But if it doesn't, you can use this code:
Code:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyA Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Text1.Text = "b"
SendKeys "{BACKSPACE}"
Else
End If
End Sub
-
Sep 6th, 2000, 03:18 PM
#5
Thread Starter
Hyperactive Member
getting closer...
well, we are getting close. the last part of the problem is the keypress even only works when you press a key and text1 has focus.
how can i use the key press even to detect a keypress even if my form doesnt have focus
(i need to detect the keypress when a user is typing in another application)
thanks again. any more help you can give would be appreciated.
-
Sep 6th, 2000, 03:25 PM
#6
You'd have to go back to using a Timer (Interval = 10?) and the GetAsyncKeyState api function.
Code:
Private Sub Timer1_Timer()
If KeyCode = vbKeyA Then
SendKeys "{BACKSPACE}" 'erase the A
SendKeys "b" 'put in the B
Else
End If
End Sub
-
Sep 6th, 2000, 04:35 PM
#7
Thread Starter
Hyperactive Member
i'm going to use this like you suggested:
Private Declare Function GetAsyncKeyState _
Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyA) Then Text1.text = "b"
End Sub
how do i loop through all the different keys to see which one was pressed (like vbkeyA - vbkeyZ and also the numbers and the $#@ stuff)
?
-
Sep 6th, 2000, 04:47 PM
#8
Code:
Private Sub Timer1_Timer()
Dim iKey As Integer
For iKey = 3 To 255
If GetAsyncKeyState(iKey) Then Debug.Print Chr(iKey)
Next
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|