Js和webview交互,实现模拟上下左右功能
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Js和webview交互,实现模拟上下左右功能,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2387字,纯文字阅读大概需要4分钟。
内容图文
JS端代码
HTMLElement.prototype.pressKey = function(code) { var evt = document.createEvent("UIEvents"); evt.keyCode = code; evt.initEvent("keydown", true, true); this.dispatchEvent(evt); } HTMLElement.prototype.upkey = function(code) { var evt = document.createEvent("UIEvents"); evt.keyCode = code; evt.initEvent("keyup", true, true); this.dispatchEvent(evt); } HTMLElement.prototype.moudown = function(x,y) { //alert("prototypeX:"+x); var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("mousedown",true,true,window,0,x,y,x,y,false,false,false,false,0,null); //alert("prototype:event"+evt); //alert("prototype:down"+evt.pageX); this.dispatchEvent(evt); } HTMLElement.prototype.mouup = function(x,y) { //var evt = document.createEvent("MouseEvents"); var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("mouseup",true,true,window,0,x,y,x,y,false,false,false,false,0,this.camera); //alert("prototype:event"+evt); //alert("prototype:down"+evt.pageX); this.dispatchEvent(evt); } HTMLElement.prototype.moumove = function(x,y) { var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("mousemove",true,true,window,0,x,y,x,y,false,false,false,false,0,null); //alert("prototype:event"+evt); //alert("prototype:down"+evt.pageX); this.dispatchEvent(evt); } function spaceDown() { document.body.pressKey(32); } function spacenUp(){ document.body.upkey(32) } function pressA(){ document.body.pressKey(37); } function upA(){ document.body.upkey(37) } function pressW(){ document.body.pressKey(38); } function upW(){ document.body.upkey(38) } function pressD(){ document.body.pressKey(39); } function upD(){ document.body.upkey(39); } function pressS(){ document.body.pressKey(40); } function upS(){ document.body.upkey(40); } function clickDown(x,y){ document.body.moudown(x,y); } function clickUp(x,y){ document.body.mouup(x,y); } function clickMove(x,y){ document.body.moumove(x,y); } function isLeft(isLeftButton){ pressLeftButton = isLeftButton; }
Android端代码
//上 38 bt_up.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()){ case MotionEvent.ACTION_DOWN: webview.loadUrl("javascript:pressW()"); break; case MotionEvent.ACTION_UP: webview.loadUrl("javascript:upW()"); break; } return true; } });
原文:https://www.cnblogs.com/liuliangliang/p/10523700.html
内容总结
以上是互联网集市为您收集整理的Js和webview交互,实现模拟上下左右功能全部内容,希望文章能够帮你解决Js和webview交互,实现模拟上下左右功能所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。