侧边栏壁纸
  • 累计撰写 781 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索

模拟触发按键

Dettan
2021-07-10 / 0 评论 / 0 点赞 / 102 阅读 / 4,978 字
温馨提示:
本文最后更新于 2022-04-30,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
屏蔽右键菜单
单击会触发双击
占满剩下的高度
b站 发弹幕
$("#chat-control-panel-vm textarea").value="12311";
$("#chat-control-panel-vm textarea").dispatchEvent(new Event('input'))

var e=document.createEvent("MouseEvents");
e.initMouseEvent("click", true, true, document.defaultView, 0, 1, 3, 16, 0,false, false, false, false, 0, null);
//var btn = document.getElementById("btn");
$("#chat-control-panel-vm button").dispatchEvent(e);





focus
e=document.createEvent("FocusEvent");
e.initEvent("focus",false,false);
e.view=window;
e.isTrusted=true;
e.composed=true;
$("#chat-control-panel-vm textarea").dispatchEvent(e);

key
1.
key: "Backspace"
2.
keyCode: 8
e = document.createEvent("KeyboardEvent");
e.initKeyboardEvent("keydown", true, false, window, '1',0,false,false,true,false,false);
e.isTrusted=true;
e.charCode = 0;
e.key='Backspace';
e.keyCode=8;
$("#chat-control-panel-vm textarea").dispatchEvent(e);
interval = setInterval(function($){
	console.log("running");
e=document.createEvent("FocusEvent");
e.initEvent("focus",false,false);
$("#chat-control-panel-vm textarea").dispatchEvent(e);

e = new window.KeyboardEvent("1",{"key":"1","code":"Numpad1","location":3,"charCode":0,"keyCode":97,"which":97});
e.initKeyboardEvent("keydown");
$("#chat-control-panel-vm textarea").dispatchEvent(e);

},2000,$);

"key", 可选,默认为 "", DOMString 类型, 设置 KeyboardEvent.key 的值。
"code", 可选,默认为 "", DOMString 类型, 设置KeyboardEvent.code 的值。
"location", 可选,默认为 0, unsigned long类型, 设置 KeyboardEvent.location 的值。
"ctrlKey", 可选,默认为 false, Boolean 类型, 设置 KeyboardEvent.ctrlKey 的值。
"shiftKey", 可选,默认为 false, Boolean 类型, 设置KeyboardEvent.shiftKey 的值。
"altKey", 可选,默认为 false, Boolean 类型, 设置 KeyboardEvent.altKey 的值。
"metaKey", 可选,默认为 false, Boolean 类型, 设置 KeyboardEvent.metaKey 的值。
"repeat", 可选,默认为 false, Boolean 类型, 设置 KeyboardEvent.repeat 的值。
"isComposing", 可选,默认为 false, Boolean 类型, 设置 KeyboardEvent.isComposing 的值。
可选,默认为 0, unsigned long 类型, 设置 KeyboardEvent.charCode (已废弃) 的值。
"keyCode", 可选,默认为 0, unsigned long 类型, 设置KeyboardEvent.keyCode (已废弃) 的值。
"which", 可选,默认为 0, unsigned long 类型, 设置KeyboardEvent.which (已废弃) 的值。




altKey: false
bubbles: true
cancelBubble: false
cancelable: true
charCode: 0
code: "Numpad1"
composed: true
ctrlKey: false
currentTarget: textarea.chat-input.border-box
defaultPrevented: false
detail: 0
eventPhase: 2
isComposing: false
isTrusted: true
key: "1"
keyCode: 97
location: 3
metaKey: false
path: (14) [textarea.chat-input.border-box, div, div.chat-input-ctnr.p-relative.chat-input-focus, div#control-panel-ctnr-box.control-panel-ctnr.border-box.p-relative.live-skin-coloration-area, div#chat-control-panel-vm.chat-control-panel, div#aside-area-vm.aside-area.p-absolute.border-box.z-aside-area, section.player-and-aside-area.p-relative.z-player-and-aside-area, div.app-body.p-relative.m-auto.z-app-body, main.app-content.p-relative.z-app-content, div.live-room-app.p-relative, body.supportWebp, html, document, Window]
repeat: false
returnValue: true
shiftKey: false
sourceCapabilities: InputDeviceCapabilities {firesTouchEvents: false}
srcElement: textarea.chat-input.border-box
target: textarea.chat-input.border-box
timeStamp: 229114.9999999907
type: "keydown"
view: Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}
which: 97
altKey: false
bubbles: false
cancelBubble: false
cancelable: false
charCode: 0
code: "Numpad1"
composed: false
ctrlKey: false
currentTarget: textarea.chat-input.border-box
defaultPrevented: false
detail: 0
eventPhase: 2
isComposing: false
isTrusted: false
key: "1"
keyCode: 97
location: 0
metaKey: false
path: (14) [textarea.chat-input.border-box, div, div.chat-input-ctnr.p-relative.chat-input-focus, div#control-panel-ctnr-box.control-panel-ctnr.border-box.p-relative.live-skin-coloration-area, div#chat-control-panel-vm.chat-control-panel, div#aside-area-vm.aside-area.p-absolute.border-box.z-aside-area, section.player-and-aside-area.p-relative.z-player-and-aside-area, div.app-body.p-relative.m-auto.z-app-body, main.app-content.p-relative.z-app-content, div.live-room-app.p-relative, body.supportWebp, html, document, Window]
repeat: false
returnValue: true
shiftKey: false
sourceCapabilities: null
srcElement: textarea.chat-input.border-box
target: textarea.chat-input.border-box
timeStamp: 838082.9999999842
type: "keydown"
view: null
which: 97
arguments[0].key.type!='focus' && arguments[0].key.indexOf('__transition') === -1

0

评论区