furley
asked on
using sendkeys
I'm having problems getting sendkeys to work in photoshop. I could get it to work in notepad. I think with Photoshop is that when it first starts up, there is a splash screen that comes up and stays there for a while. During that time, I'm using sendkeys to photoshop and they're not getting through. Below is the code.
Private Sub cmdNotePad_Click()
Dim RetVal
RetVal = Shell("Notepad.exe", 1)
SendKeys "ab", True
SendKeys "%fa", True
End Sub
Private Sub cmdPhotoshop_Click()
Dim RetVal
RetVal = Shell("D:\Program Files\Adobe\Photoshop 5.0\Photoshp.exe", 1)
SendKeys "%fn", True
End Sub
My question is how do I wait for that splash screen to go away and then send the sendkeys command?
Private Sub cmdNotePad_Click()
Dim RetVal
RetVal = Shell("Notepad.exe", 1)
SendKeys "ab", True
SendKeys "%fa", True
End Sub
Private Sub cmdPhotoshop_Click()
Dim RetVal
RetVal = Shell("D:\Program Files\Adobe\Photoshop 5.0\Photoshp.exe", 1)
SendKeys "%fn", True
End Sub
My question is how do I wait for that splash screen to go away and then send the sendkeys command?
Doesn't Photoshop have an ActiveX/OLE interface you can use to communicate with it? (I know it doesn't answer your sendkeys, but that would be the way to use it)
ASKER
yes it does. It's called OLE Automation. Even if I use it, I would still need to use sendkeys. Unfortunately, Photoshop's support for OLE doesn't seem to be very reliable. I've tried the above code on Word, which has a splash screen come up and everything worked fine, so it may not be a splash screen problem.
Change your code to look like this:
Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Private Sub cmdPhotoshop_Click()
Dim RetVal
RetVal = Shell("D:\Program Files\Adobe\Photoshop 5.0\Photoshp.exe", 1)
'The 3000 makes it sleep for 3 seconds. Add for longer sleep
Sleep 3000
SendKeys "%fn", True
End Sub
Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Private Sub cmdPhotoshop_Click()
Dim RetVal
RetVal = Shell("D:\Program Files\Adobe\Photoshop 5.0\Photoshp.exe", 1)
'The 3000 makes it sleep for 3 seconds. Add for longer sleep
Sleep 3000
SendKeys "%fn", True
End Sub
ASKER
That didn't work. I don't think the splash screen is the problem and I don't think there's anything wrong with the code. I think there's something wrong with Photoshop.
Try the keyb_event, I think this should work in photoshop
' in a bas module past
Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
' your code
Private Sub cmdNotePad_Click()
Dim RetVal
RetVal = Shell("Notepad.exe", 1)
keybd_event 65, 0, 0, 0 'A press Down
keybd_event 65, 0, 2, 0 'A released
keybd_event 66, 0, 0, 0 'B press Down
keybd_event 66, 0, 2, 0 'B released
keybd_event 18, 0, 0, 0 'Alt press Down
keybd_event 70, 0, 0, 0 'f press Down
keybd_event 65, 0, 0, 0 'A press Down
keybd_event 70, 0, 2, 0 'f released
keybd_event 65, 0, 2, 0 'A released
keybd_event 18, 0, 2, 0 'Alt released
End Sub
Private Sub cmdPhotoshop_Click()
Dim RetVal
RetVal = Shell("D:\Program Files\Adobe\Photoshop 5.0\Photoshp.exe", 1)
SendKeys "%fn", True
End Sub
' in a bas module past
Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
' your code
Private Sub cmdNotePad_Click()
Dim RetVal
RetVal = Shell("Notepad.exe", 1)
keybd_event 65, 0, 0, 0 'A press Down
keybd_event 65, 0, 2, 0 'A released
keybd_event 66, 0, 0, 0 'B press Down
keybd_event 66, 0, 2, 0 'B released
keybd_event 18, 0, 0, 0 'Alt press Down
keybd_event 70, 0, 0, 0 'f press Down
keybd_event 65, 0, 0, 0 'A press Down
keybd_event 70, 0, 2, 0 'f released
keybd_event 65, 0, 2, 0 'A released
keybd_event 18, 0, 2, 0 'Alt released
End Sub
Private Sub cmdPhotoshop_Click()
Dim RetVal
RetVal = Shell("D:\Program Files\Adobe\Photoshop 5.0\Photoshp.exe", 1)
SendKeys "%fn", True
End Sub
where did you get those numbers for each keybd_event?
in vb help, do a search for "Key Codes" then select the "key codes constants" its a great list.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.