Using PostMessage to Send a Control Key + Alpha to WordPad using VBA?

121 views Asked by At

Regardless that discussion of this & similar issues are near ubiquitous, I am unable find a working solution... using PostMessage / SendMessage (because they send directly to designated hwnd (unlike SendInput or Sendkeys). There are a small minority of postings that suggest it cannot be done, but so many conversations on HOW to send a simple CNTL + 'U', for example, to WordPad. At this point, I would even welcome a definitive IT CAN'T BE DONE.

Running Windows7, MS Office 2016

Have succesfully sent Text to WordPad using: WM_KEYDOWN=&H100, _KEYUP=&H101, _CHAR=&H102 vbKEYCONTROL=&H17, hwnd=Wordpad Edit Window Handle

PostMessage hwnd, WM_CHAR, Asc("A"), 0 and

 PostMessage hwnd, WM_KEYDOWN, VBA.vbKeyU,0
 PostMessage hwnd, WM_KEYUP, VBA.vbKeyU,0

But trying to send Control Key & a character ALL FAIL:

 PostMessage(hwnd, WM_KEYDOWN, vbKeyControl, 0)
 PostMessage hwnd, WM_KEYDOWN, VBA.vbKeyU,0
 PostMessage hwnd, WM_KEYUP, VBA.vbKeyU,0
 PostMessage(hwnd, WM_KEYUP, vbKeyControl, 0)
 PostMessage hwnd, &H112, &HF100, &H46
 PostMessage hwnd, WM_KEYDOWN, Asc("H"),0

&h112=WM_SYSCOMMAND, &HF100=SC_KEYMENU, &H46='H'

 Dim tCurKB(255) As Byte, tInitKB(255)  As Byte
 Dim lThreadID As Long
 GetKeyboardState tInitKB(0)
 tCurKB(VK_CONTROL) = &H80
 SetKeyboardState tCurKB(0)
PostMessage hwnd,WM_CHAR, , 1, vbKeyControl

Although Excel responds to the Locked Control Key from the above Set KeyBoardState, WordPad does not.

0

There are 0 answers