Page 1 of 3

send CTRL-C to dchtmlviewer

Posted: Tue Mar 03, 2020 1:28 pm
by skiman
Hi,

I would like to send a PAGE-DOWN to a dchtmlviewer.

Code: Select all

postappevent(xbeP_Keyboard,xbeK_PGDN,,oViewer)
The above isn't working, nothing happens. Would this be possible to accomplish?

Re: send CTRL-C to dchtmlviewer

Posted: Tue Mar 03, 2020 8:50 pm
by Auge_Ohr
skiman wrote:I would like to send a PAGE-DOWN to a dchtmlviewer.

Code: Select all

postappevent(xbeP_Keyboard,xbeK_PGDN,,oViewer)
The above isn't working, nothing happens. Would this be possible to accomplish?
if you want to "send" Key they must be "virtual" -> VK_

Code: Select all

#define VK_PRIOR 0x21
#define VK_NEXT 0x22
#define VK_UP 0x26
#define VK_DOWN 0x28
and you canĀ“t use PostAppEvent() while that is Xbase++ only.

Re: send CTRL-C to dchtmlviewer

Posted: Wed Mar 04, 2020 1:58 am
by skiman
Hi Jimmy,

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?

Re: send CTRL-C to dchtmlviewer

Posted: Wed Mar 04, 2020 4:01 am
by Tom
Are you sure the dchtmlviewer knows keyboard-events? What about posting them to the scrollbar?

Re: send CTRL-C to dchtmlviewer

Posted: Wed Mar 04, 2020 6:26 am
by rdonnay
I looked at the docs for XbpHtmlViewer and XbpActiveXControl and there is nothing documented on how to send a key to an ActiveX object.

I also looked online and can find nothing.

Re: send CTRL-C to dchtmlviewer

Posted: Wed Mar 04, 2020 5:27 pm
by Auge_Ohr
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?
have a look at c:\exp20\Samples\HtmlEdit_2\ from J.A. Diego Kerejeta.

it is a HTML Editor based on XbpHTMLViewer() and use "virtual Key"
INPUT Structure is used instead of keybd_event (), which is deprecated, so it need Ot4Xb

---

include "self made" Help File from ieFrame.DLL
look at "Webbrowser" which Event, Method or Property are available
shdocvw.zip
(131.8 KiB) Downloaded 675 times

Re: send CTRL-C to dchtmlviewer

Posted: Fri Mar 06, 2020 3:35 am
by skiman
Hi Jimmy,

Thanks, I will check that sample.

Re: send CTRL-C to dchtmlviewer

Posted: Wed Mar 18, 2020 10:43 am
by skiman
Hi,

Meanwhile I found the following C# code to send CTRL-C to an external application. It should put already selected text to the Windows clipboard.

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

}
I suppose this should be possible to convert to Xbase++.

Another possible solution I found was the following code:

The author wrote the following:
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:
And this is his code:

Code: Select all

static void fetchSelectionToClipboard()
{
  Thread.Sleep(400);
  SendKeys.SendWait("^c");   // magic line which copies selected text to clipboard
  Thread.Sleep(400);
}
I don't know how to simulate that sendkeys function.

If anyone have the knowledge to convert this to Xbase++, It would be a nice to have.

I would use it to send selected text in a dchtmlviewer to the clipboard, so I can import it, but I suppose it would be usefull for other situations also.

Re: send CTRL-C to dchtmlviewer

Posted: Wed Mar 18, 2020 10:52 am
by rdonnay
I looked at that C# code a few weeks ago but could find nothing in the Xbase++ docs that shows how to send it to an XbpActiveXControl object or Automation Object.

Re: send CTRL-C to dchtmlviewer

Posted: Wed Mar 18, 2020 11:56 am
by skiman
Hi,

In the htmleditor of J.A. Diego Kerejeta , I found the following. It is used to send a CTRL-C to the xbphtmlviewer.

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