What are some ways to retain focus on an application, while using the sendkeys statement?
The application has been started with an appactivate (appid).
Printable View
What are some ways to retain focus on an application, while using the sendkeys statement?
The application has been started with an appactivate (appid).
Don't use sendkeys use sendmessage like this:
Private Const WM_IME_CHAR = &H286
mTargetHwnd = text1.hwnd
SendMessage mTargetHwnd, WM_IME_CHAR, Asc(sCharacter), 0
If you want to send Alts and Ctrl just use spy++ to monitor what is been sent to a test app.
Rob
Yes, I am using Alt ie, %(f+x){Tab} etc.
Do I send the same string?
How will spy++ help me, or would I have to add alot of code?
If you need to send teh following:
CTRL + A
SendMessage mTargetHwnd, WM_CHAR, Asc(LCase$("A")) - 96, 0
A:
SendMessage mTargetHwnd, WM_IME_CHAR, Asc("A"), 0
Enter:
SendMessage mTargetHwnd, WM_CHAR, VK_RETURN, 0
Tab:
SendMessage mFormHwnd, WM_IME_KEYDOWN, VK_TAB, 0
Shift + Tab is a little more tricky:
SetForegroundWindow mFormHwnd
keybd_event VK_SHIFT, 0, 0, 0 'press shift
keybd_event VK_TAB, 0, 0, 0 'press tab
keybd_event VK_SHIFT, 0, 2, 0 'release shift
Spy ++ looks at what messages are sent to a window - almost everything you do can be done in either a sendmessage or a postmessage - with spy ++ you can see these messages and use the functions to send them yourself.
If the code needs too much changing you might aswell stay with sendkeys. Before each sendkeys statement do a SetForegroundWindow me.hwnd to stay focused.