I would like to send a PAGE-DOWN to a dchtmlviewer.
Code: Select all
postappevent(xbeP_Keyboard,xbeK_PGDN,,oViewer)
Code: Select all
postappevent(xbeP_Keyboard,xbeK_PGDN,,oViewer)
if you want to "send" Key they must be "virtual" -> VK_skiman wrote:I would like to send a PAGE-DOWN to a dchtmlviewer.The above isn't working, nothing happens. Would this be possible to accomplish?Code: Select all
postappevent(xbeP_Keyboard,xbeK_PGDN,,oViewer)
Code: Select all
#define VK_PRIOR 0x21
#define VK_NEXT 0x22
#define VK_UP 0x26
#define VK_DOWN 0x28
have a look at c:\exp20\Samples\HtmlEdit_2\ from J.A. Diego Kerejeta.skiman wrote: Thanks for the answer, but I have no idea how to send a 'virtual key'.
I looked around and found samples in VB, which are using Sendkeys to send keys to another application. Do you have a sample?
Code: Select all
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static public extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
.....
private void SendCtrlC(IntPtr hWnd)
{
uint KEYEVENTF_KEYUP = 2;
byte VK_CONTROL = 0x11;
SetForegroundWindow(hWnd);
keybd_event(VK_CONTROL,0,0,0);
keybd_event (0x43, 0, 0, 0 ); //Send the C key (43 is "C")
keybd_event (0x43, 0, KEYEVENTF_KEYUP, 0);
keybd_event (VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);// 'Left Control Up
}
And this is his code:No idea for how long has this been possible but instead of fighting with Win32 programming (mostly user32.dll and various Windows messages like WM_GETTEXT, WM_COPY and various SendMessage(handle, WM_GETTEXT, maxLength, sb) calls) which is advised in most of SO threads on this topic, I easily managed to access selected text in any window in my C# code followingly:
Code: Select all
static void fetchSelectionToClipboard()
{
Thread.Sleep(400);
SendKeys.SendWait("^c"); // magic line which copies selected text to clipboard
Thread.Sleep(400);
}
Code: Select all
*****************************
PROCEDURE SendCtrlKey( xKey )
*****************************
LOCAL oInput := Input():New()
LOCAL nEvents:= 4
LOCAL nSize := oInput:_sizeof_()
LOCAL pBuffer:= _xgrab( nSize * nEvents )
oInput:_link_( pBuffer , .F.)
oInput:type := INPUT_KEYBOARD
oInput:ki:wVk:= VK_CONTROL
GwstArrayNext(oInput)
oInput:type := INPUT_KEYBOARD
oInput:ki:wVk:= xKey
GwstArrayNext(oInput)
oInput:type := INPUT_KEYBOARD
oInput:ki:wVk := VK_CONTROL
oInput:ki:dwFlags:= KEYEVENTF_KEYUP
GwstArrayNext(oInput)
oInput:type := INPUT_KEYBOARD
oInput:ki:wVk := xKey
oInput:ki:dwFlags:= KEYEVENTF_KEYUP
@user32:SendInput( nEvents, pBuffer, nSize )
oInput:_unlink_()
_xfree( pBuffer)
RETURN
*********************
BEGIN STRUCTURE INPUT
*********************
MEMBER DWORD type
BEGIN UNION
MEMBER @ MOUSEINPUT mi
MEMBER @ KEYBDINPUT ki
MEMBER @ HARDWAREINPUT hi
END UNION
END STRUCTURE // 28 // BYTES