Code Monkey home page Code Monkey logo

Comments (5)

manakanemu avatar manakanemu commented on July 18, 2024

抱歉我无法复现你的问题,我使用如下代码:

$(document).keydown(function(event){
    console.log(event.keyCode);
});

无论鼠标焦点在哪都能正常监听所有键盘事件,即使绑定在输入的textarea上,也能正常监听键盘。
浏览器是chrome 87.0.4280.67

from bilibilivtuberlivetool.

KittyEar avatar KittyEar commented on July 18, 2024

from bilibilivtuberlivetool.

manakanemu avatar manakanemu commented on July 18, 2024

b站是用vue劫持事件的,它定义的keydown事件

 e.prototype.onKeyDown = function(t) {
            13 === t.keyCode && (t.preventDefault(),
            this.sendDanmaku(t).then(z.noop).catch(z.noop))
        }

在检测到回车的时候会提交弹幕内容并且清空textarea,等他的keydown事件执行完了再执行你的keydown事件,自然就读不到东西了。如果你单纯就是想知道发送了什么,可以去读网站的vue变量,b站在聊天框上绑定了一个vue变量,用.lastMsgContent属性可以看到上一次发送了什么。

from bilibilivtuberlivetool.

KittyEar avatar KittyEar commented on July 18, 2024

from bilibilivtuberlivetool.

manakanemu avatar manakanemu commented on July 18, 2024

客气,我平时没事儿也喜欢捣鼓捣鼓b站相关的js脚本,以后可以多交流。

from bilibilivtuberlivetool.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.