Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
905fa222
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
905fa222
编写于
10月 09, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
U: demo chromium模拟事件
上级
11da3423
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
8 deletion
+46
-8
example/mockevent/mockevent.go
example/mockevent/mockevent.go
+42
-4
example/mockevent/resources/index.html
example/mockevent/resources/index.html
+4
-4
未找到文件。
example/mockevent/mockevent.go
浏览文件 @
905fa222
...
...
@@ -8,6 +8,8 @@ import (
"github.com/energye/energy/v2/cef/ipc/target"
"github.com/energye/energy/v2/cef/ipc/types"
"github.com/energye/energy/v2/consts"
t
"github.com/energye/energy/v2/types"
lcltypes
"github.com/energye/golcl/lcl/types"
)
//go:embed resources
...
...
@@ -55,12 +57,14 @@ func main() {
btn2
:=
body
.
GetDocument
()
.
GetElementById
(
"btn2"
)
btn3
:=
body
.
GetDocument
()
.
GetElementById
(
"btn3"
)
inpText
:=
body
.
GetDocument
()
.
GetElementById
(
"inpText"
)
inp2Text
:=
body
.
GetDocument
()
.
GetElementById
(
"inp2Text"
)
fmt
.
Println
(
"inpText"
,
inpText
.
GetElementBounds
())
var
doms
=
make
(
map
[
string
]
cef
.
TCefRect
)
doms
[
"btn1"
]
=
btn1
.
GetElementBounds
()
doms
[
"btn2"
]
=
btn2
.
GetElementBounds
()
doms
[
"btn3"
]
=
btn3
.
GetElementBounds
()
doms
[
"inpText"
]
=
inpText
.
GetElementBounds
()
doms
[
"inp2Text"
]
=
inp2Text
.
GetElementBounds
()
ipc
.
EmitTarget
(
"renderLoadEnd"
,
target
.
NewTargetMain
(),
browserId
,
channelId
,
doms
)
})
frame
.
VisitDom
(
visitor
)
...
...
@@ -78,14 +82,12 @@ func main() {
}
// 模拟按钮点击事件
var
buttonClickEvent
=
func
(
domRect
cef
.
TCefRect
)
{
// 页面加载完之后
window
.
RunOnMainThread
(
func
()
{
//在UI主线程
window
.
RunOnMainThread
(
func
()
{
//在UI主线程执行
chromium
:=
window
.
Chromium
()
// 鼠标事件
me
:=
&
cef
.
TCefMouseEvent
{}
// 设置元素坐标,元素坐标相对于窗口,这里取元素中间位置
me
.
X
,
me
.
Y
=
domXYCenter
(
domRect
)
fmt
.
Println
(
"buttonClickEvent"
,
me
)
// 模拟鼠标到指定位置
chromium
.
SendMouseMoveEvent
(
me
,
false
)
// 模拟鼠标双击事件
...
...
@@ -95,12 +97,32 @@ func main() {
chromium
.
SendMouseClickEvent
(
me
,
consts
.
MBT_LEFT
,
true
,
1
)
})
}
// 模拟文本输入
var
inputTextEvent
=
func
(
value
string
,
domRect
cef
.
TCefRect
)
{
// 文本框区域点击
buttonClickEvent
(
domRect
)
window
.
RunOnMainThread
(
func
()
{
//在UI主线程执行
chromium
:=
window
.
Chromium
()
// 鼠标事件
me
:=
&
cef
.
TCefMouseEvent
{}
// 设置元素坐标,元素坐标相对于窗口,这里取元素中间位置
me
.
X
,
me
.
Y
=
domXYCenter
(
domRect
)
// 一个一个字符设置
for
_
,
v
:=
range
value
{
chromium
.
SendKeyEvent
(
keyPress
(
string
(
v
)))
}
})
}
ipc
.
On
(
"renderLoadEnd"
,
func
(
browserId
int32
,
channelId
int64
,
doms
map
[
string
]
cef
.
TCefRect
)
{
fmt
.
Println
(
"doms"
,
doms
)
// 按钮
buttonClickEvent
(
doms
[
"btn1"
])
buttonClickEvent
(
doms
[
"btn2"
])
buttonClickEvent
(
doms
[
"btn3"
])
// 文本框
inputTextEvent
(
"我爱中国"
,
doms
[
"inp2Text"
])
//中文
inputTextEvent
(
"energy.yanghy.cn"
,
doms
[
"inpText"
])
//英文
// 滚动条
// 回复到渲染进程执行成功, 触发是Go的事件.
ipc
.
EmitTarget
(
"repayMockIsSuccess"
,
target
.
NewTarget
(
browserId
,
channelId
,
target
.
TgGoSub
))
})
...
...
@@ -108,3 +130,19 @@ func main() {
//运行应用
cef
.
Run
(
app
)
}
func
keyPress
(
key
string
)
*
cef
.
TCefKeyEvent
{
utf8Key
:=
&
lcltypes
.
TUTF8Char
{}
utf8Key
.
SetString
(
key
)
event
:=
&
cef
.
TCefKeyEvent
{}
var
asciiCode
int
fmt
.
Sscanf
(
utf8Key
.
ToString
(),
"%c"
,
&
asciiCode
)
event
.
Kind
=
consts
.
KEYEVENT_CHAR
event
.
WindowsKeyCode
=
t
.
Int32
(
asciiCode
)
event
.
NativeKeyCode
=
0
event
.
IsSystemKey
=
0
event
.
Character
=
'0'
event
.
UnmodifiedCharacter
=
'0'
event
.
FocusOnEditableField
=
1
// 0=false, 1=true
return
event
}
example/mockevent/resources/index.html
浏览文件 @
905fa222
...
...
@@ -11,11 +11,11 @@
</script>
</head>
<body>
<button
onclick=
"btnClick(this)"
id=
"btn1"
>
Button1
</button>
<button
onclick=
"btnClick(this)"
id=
"btn2"
>
Button2
</button>
<button
onclick=
"btnClick(this)"
id=
"btn3"
>
Button3
</button>
<br>
<button
onclick=
"btnClick(this)"
id=
"btn1"
style=
"position: absolute;top: 100px;left: 100px"
>
Button1
</button>
<button
onclick=
"btnClick(this)"
id=
"btn2"
style=
"position: absolute;top: 300px;left: 150px"
>
Button2
</button>
<button
onclick=
"btnClick(this)"
id=
"btn3"
style=
"position: absolute;top: 500px;left: 200px"
>
Button3
</button>
<input
type=
"text"
id=
"inpText"
><br>
<input
type=
"text"
id=
"inp2Text"
style=
"position: absolute;top: 40px;left: 90px"
><br>
<div
id=
"msg"
></div>
</body>
</html>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录