How would you detect keypresses when another applacation has focus?
For example Ctrl-v.
I'm trying to make a 3ed party pasting program for a game called PlaneShift that dosen't currently have any copy or past support.
Printable View
How would you detect keypresses when another applacation has focus?
For example Ctrl-v.
I'm trying to make a 3ed party pasting program for a game called PlaneShift that dosen't currently have any copy or past support.
How can a program receive a keyboard input if the program does not have Focus?
Or do you mean, prog-A receive a keyboard input and send it to prog-b ?
Boys,
you can send a CTRL + V to a form even if it does not have focus as follows.
Code:SendMessage(hwnd,WM_CHAR, 22, 0, 0) ' Ctrl+c =3 , Ctrl+X=24, ctrl + v=22
I believe I've seen code for hooking keyboard events, even when your own app doesn't have focus.
But I've never used it.
Try searching for 'Key Logger' code
Longwolf has the idea.
and its
Quote:
How can a program receive a keyboard input if the program does not have Focus?
here's a search I did at PSC. May have something you can use
http://www.planet-source-code.com/vb...=Keyboard+hook
Wouldn't something like this work?
Code:Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Timer1_Timer()
Static KeysInUse As Boolean
If GetAsyncKeyState(vbKeyControl) < 0 And GetAsyncKeyState(vbKeyV) < 0 Then
If KeysInUse = False Then
KeysInUse = True
Debug.Print "Control+V Pressed"
' Call Your Sub/Function here
Exit Sub
End If
Else
KeysInUse = False
End If
End Sub
Is there anyway to make it more event driven?
Does the program have focus?
If not, Timer, or something needs to be sent to it so an event will occur.
How can an event happen?
Timer, mouse move, key pressed, program received somthing via 'SendMessage',.....
The game would have the focus, so no.
You mean to say that you want to detect if ctrl+v is pressed while the game is in focus?
Correct.
Edgemeal's method works, but the timer needs to be set to a very fast speed in order for the program to respond to it. Right now I have the timer set to 10.
how about a global hotkey
most likely you want to detect a combination of keys being pressed - a hotkey it doesnt matter which app has focus.
Have you tried the suggestion of longwolf in post #6?