Key input not working as expected in ActiveX IE Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Key input not working as expected in ActiveX IE

28 Jan 2018, 16:26

I am making a gui for an ahk application using IE to display a html document through an ActiveX control.
My problem is that when I display the page in my gui Tab does not navigate the page and both Ctrl+C and Ctrl+V does not work in the input fields,
I can still use the context menu to copy paste, I think that the Tab issue is because it is navigating the ahk gui instead of the html page, but I can't think of a reason that Ctrl+C and Ctrl+V don't work.
I do not experience this issue when displaying the page in a non ActiveX IE.

Script

Code: Select all

Gui, 1:New, +Resize, ActiveX Example
Gui, Margin, 0, 0
Gui, Add, ActiveX, vIE w500 h500, Shell.Explorer

IE.Navigate(A_ScriptDir "\page.html")
While(IE.ReadyState != 4 || this.IE.Busy) {
    Sleep, 20
}

Gui, Show, AutoSize
return

GuiSize:
    GuiControl, Move, IE, % "w" A_GuiWidth " h" A_GuiHeight
return

GuiClose:
    ExitApp
Html Page

Code: Select all

<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
	</head>
	<body>
		<form>
			<input type="text" id="channel-name"      placeholder="Enter name">
			<input type="text" id="channel-link"      placeholder="Enter link">
			<input type="text" id="channel-condition" placeholder="ALL">
		</form>
	</body>
</html>
Please excuse my spelling I am dyslexic.
93270

Re: Key input not working as expected in ActiveX IE  Topic is solved

28 Jan 2018, 16:44

You need https://github.com/Lexikos/AutoHotkey-R ... c.ahk#L347 with OnMessage(0x100, "gui_KeyDown", 2)

The regex in gui_KeyDown needs fixing to allow Ctrl+C and it's looking for an Shell.Explorer object with the name of wb, not IE.
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: Key input not working as expected in ActiveX IE

28 Jan 2018, 17:56

Thank you it is working now

Code: Select all

Gui, 1:New, +Resize, ActiveX Example
Gui, Margin, 0, 0
Gui, Add, ActiveX, vIE w500 h500, Shell.Explorer

FuncObj := Func("gui_KeyDown").Bind(IE)
OnMessage(0x100, FuncObj, 2)

IE.Navigate(A_ScriptDir "\page.html")
While(IE.ReadyState != 4 || this.IE.Busy) {
    Sleep, 20
}

Gui, Show, AutoSize
return

GuiSize:
    GuiControl, Move, IE, % "w" A_GuiWidth " h" A_GuiHeight
return

GuiClose:
    ExitApp

gui_KeyDown(wb, wParam, lParam, nMsg, hWnd) {
	if (Chr(wParam) ~= "[BD-UW-Z]" || wParam = 0x74) ; Disable Ctrl+O/L/F/N and F5.
		return
	Gui +OwnDialogs ; For threadless callbacks which interrupt this.
	pipa := ComObjQuery(wb, "{00000117-0000-0000-C000-000000000046}")
	VarSetCapacity(kMsg, 48), NumPut(A_GuiY, NumPut(A_GuiX
	, NumPut(A_EventInfo, NumPut(lParam, NumPut(wParam
	, NumPut(nMsg, NumPut(hWnd, kMsg)))), "uint"), "int"), "int")
	Loop 2
	r := DllCall(NumGet(NumGet(1*pipa)+5*A_PtrSize), "ptr", pipa, "ptr", &kMsg)
	; Loop to work around an odd tabbing issue (it's as if there
	; is a non-existent element at the end of the tab order).
	until wParam != 9 || wb.Document.activeElement != ""
	ObjRelease(pipa)
	if r = 0 ; S_OK: the message was translated to an accelerator.
		return 0
}
Please excuse my spelling I am dyslexic.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Key input not working as expected in ActiveX IE

28 Jan 2018, 19:17

Using ComObjConnect instead:

Code: Select all

#NoEnv
#SingleInstance force
SetWorkingDir % A_ScriptDir
SendMode, Input
CoordMode, ToolTip, Screen
#Warn
; Windows 8.1 64 bit - Autohotkey v1.1.27.04 32-bit Unicode


Gui, 1:New, +Resize, ActiveX Example
Gui, Margin, 0, 0
Gui, Add, ActiveX, vIE w500 h500, Shell.Explorer 
IE.Navigate(A_ScriptDir "\page.html")
while (IE.Busy or IE.ReadyState <> 4)
    Sleep, 100
doc:=IE.document ; it seems that ComObjConnect's 'ComObject ' parameter admits only a single variable reference
ComObjConnect(doc, {"onkeypress": Func("__keyPress")}) ; 'prefix' parameter can be a user-defined object, as per the documentation
Gui, Show, AutoSize
return

GuiSize:
	GuiControl, Move, IE, % "w" A_GuiWidth " h" A_GuiHeight
return
GuiClose:
	ExitApp

__keyPress(__userDefinedObject, __target) { ; the target is the document in this case
static __keys := {1:"selectall", 3:"copy", 22:"paste", 24:"cut"}
if (__keys.HasKey(__keyCode:=__target.parentWindow.event.keyCode))
	__target.ExecCommand(__keys[__keyCode])
} ; cf. https://autohotkey.com/board/topic/76777-help-with-copy-and-pasting-with-shellexplorer/?p=488306
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, Rohwedder and 240 guests