A
Alain Bourgeois
Dear all,
I would like to send keystrokes to another application. I tried to send
keystroke on space bar and home key, but it does not work: the other
application doesn't receive anything!
Here is the code I used:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal
lpClassName As Any, ByVal lpwindowname As String) As Long
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Function getHandleVD() As Long
getHandleVD = FindWindow(0&, "VirtualDub 1.9.5 - [S_3P_0-0.avi]")
End Function
Function SendKey(Key As Long)
Dim L As Long
L = getHandleVD
' in debug mode I see L is not null
If L <> 0& Then
Call SendMessage(L, &H100, Key, 0) 'send key DOWN to application
Call Sleep(500) ' wait a little bit
Call SendMessage(L, &H101, Key, 0) 'send key UP down to application
End If
End Function
'-----------------------------------------------------------------
Function SendHome()
SendKey (&H24)
End Function
Function SendEnd()
SendKey (&H23)
End Function
Function SendEnter()
SendKey (&HD)
End Function
Function SendSpace()
SendKey (&H20)
End Function
From a macro, call functions SendHome, SendEnd,SendEnter, SendSpace, NOTHING
happens (however, pressing space in the application has an effect).
I also tried Call SendMessage(L, &HC, 0, " ") to send space, but I get a
runtime error telling lparam type is wrong. If I set LParam as any, I cannot
compile Call SendMessage(L, &H101, Key, 0).
I also tried without Sleep
So my question is : how can I do this using SendMessage? (I cannot use vb's
SendKeys function: for this I should first use AppActivate but this gives a
runtime error bcs the window I want to activate is busy playing a video).
Regards,
Alain
I would like to send keystrokes to another application. I tried to send
keystroke on space bar and home key, but it does not work: the other
application doesn't receive anything!
Here is the code I used:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal
lpClassName As Any, ByVal lpwindowname As String) As Long
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Function getHandleVD() As Long
getHandleVD = FindWindow(0&, "VirtualDub 1.9.5 - [S_3P_0-0.avi]")
End Function
Function SendKey(Key As Long)
Dim L As Long
L = getHandleVD
' in debug mode I see L is not null
If L <> 0& Then
Call SendMessage(L, &H100, Key, 0) 'send key DOWN to application
Call Sleep(500) ' wait a little bit
Call SendMessage(L, &H101, Key, 0) 'send key UP down to application
End If
End Function
'-----------------------------------------------------------------
Function SendHome()
SendKey (&H24)
End Function
Function SendEnd()
SendKey (&H23)
End Function
Function SendEnter()
SendKey (&HD)
End Function
Function SendSpace()
SendKey (&H20)
End Function
From a macro, call functions SendHome, SendEnd,SendEnter, SendSpace, NOTHING
happens (however, pressing space in the application has an effect).
I also tried Call SendMessage(L, &HC, 0, " ") to send space, but I get a
runtime error telling lparam type is wrong. If I set LParam as any, I cannot
compile Call SendMessage(L, &H101, Key, 0).
I also tried without Sleep
So my question is : how can I do this using SendMessage? (I cannot use vb's
SendKeys function: for this I should first use AppActivate but this gives a
runtime error bcs the window I want to activate is busy playing a video).
Regards,
Alain