键盘事件监听

There are 3 types of events when interacting with keyboard events:

与键盘事件进行交互时,有3种类型的事件:

  • keydown the keyboard key has been pressed

    keydown键盘键被按下

  • keyup the keyboard key has been released

    keyup键盘按键已被释放

keydown is also fired when the key repeats while the button stays pressed.

keydown也发射时的键重复而按钮保持按下。

While mouse and touch events are typically listened on a specific element, it’s common to listen for keyboard events on the document:

尽管通常在特定元素上侦听鼠标和触摸事件,但在文档上侦听键盘事件是很常见的:

document.addEventListener('keydown', event => {// key pressed
})

The parameter passed to the event listener is a KeyboardEvent.

传递给事件侦听器的参数是KeyboardEvent 。

This event object, in addition to the Event object properties offers us (among others) these unique properties:

除了“ 事件”对象的属性外,该事件对象还为我们提供了以下这些独特的属性:

  • altKey true if alt key was pressed when the event was fired

    altKey如果触发事件时按下alt键, altKey true

  • code the code of the key pressed, returned as a string

    code所按下键的编码,以字符串形式返回

  • ctrlKey true if ctrl key was pressed when the event was fired

    ctrlKey如果触发事件时按下ctrl键,则为true

  • key the value of the key pressed, returned as a string

    key所按下key的值,以字符串形式返回

  • locale the keyboard locale value

    locale键盘语言环境值

  • location the location of the key on the keyboard

    location键盘上按键的位置

  • metaKey true if meta key was pressed when the event was fired

    metaKey如果触发事件时按下了meta键, metaKey true

  • repeat true if the key has been repeated (e.g. the key has not been released)

    repeat如果该键已经被重复真(如钥匙尚未发布)

  • shiftKey true if shift key was pressed when the event was fired

    shiftKey如果触发事件时按下Shift键,则为true

This demo is a keylogger which will show you the values of some of the properties I listed above:

该演示是一个键盘记录程序,它将向您显示我上面列出的某些属性的值:

See the Pen Key logger demo by Flavio Copes (@flaviocopes) on CodePen.

见笔键盘记录演示由弗拉维奥科佩斯( @flaviocopes上) CodePen 。

翻译自: https://flaviocopes.com/keyboard-events/

键盘事件监听

键盘事件监听_键盘事件相关推荐

  1. java按钮点击事件监听_按钮事件监听

    [java]代码库/** * 功能:按钮事件监听 */ package com.test; import java.awt.*; import javax.swing.*; import java.a ...

  2. Java 创建事件Event、事件监听EventListener、事件发布publishEvent

    一.概述 个人认为,事件机制一般可由:事件源source,事件对象Event,事件监听EventListener,事件发布publishEvent组成 事件源:引起事件发生的源: User用户信息, ...

  3. 安卓键盘事件监听,键盘弹出收起

    一.键盘事件监听 1.在mainifest.xml 中设置activity模式 ```<activityandroid:name=".ui.activity.MainActivity& ...

  4. Java_基础—GUI(窗体/鼠标/键盘/动作监听和键盘事件)

    一.窗体监听 Frame f = new Frame("我的窗体"); //事件源是窗体,把监听器注册到事件源上 //事件对象传递给监听器 package com.soar.gui ...

  5. 移除元素所有事件监听_前端日记—DOM 事件机制和事件委托

    DOM事件机制 事件指的就是就是onclick,onmouseover,onmouseout等. 2002年W3C规定了浏览器的事件调用顺序标准,这其中有两个关键术语. 事件捕获:简单一点解释事件捕获 ...

  6. 键盘-App监听软键盘按键的三种方式

    前言: 我们在android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的"GO"按键加载url页面:在点击搜索框的时候,点 ...

  7. java事件监听机制pdf,事件监听机制(转)

    事件监听机制在java编程中有很重要的应用,一般我们在处理GUI编程时,只是重写一下监听接口的perform函数即可.但事件监听在底层是如何运行的?通过下面的例子我们可以有个清楚地了解. 1.     ...

  8. 事件监听机制——鼠标事件MouseEvent

    鼠标事件 鼠标事件包括鼠标的双击.左击.右击.中间键等等,本文进行事件加载进行简单介绍,具体可以参考键盘事件. import java.awt.*; import java.awt.event.*;/ ...

  9. android 后台键盘按键监听,android键盘的监听

    android 键盘监听 从知乎上看到的一种解决方案,目前还没发现有什么坑. public class SoftKeyBroadManager implements ViewTreeObserver. ...

最新文章

  1. 设置本地用户帐户的过期日期
  2. 监督分类空白处也被分类了_用于半监督短文本分类的异构图注意网络
  3. RxJava使用(一)基本使用
  4. unity, 什么时候用静态类,什么时候用单例
  5. P2221 [HAOI2012]高速公路
  6. 【每周CV论文】初学深度学习图像修复应该要读的文章
  7. pandas输出csv某一列的数据
  8. 2019 Multi-University Training Contest 1 - 1001 - Blank - dp
  9. 人工智能ai 学习_学习代理| 人工智能
  10. 装修时水电如何开槽?沟槽如何封堵?有哪些防止沟槽开裂的方法
  11. codeblocks主题修改(vim)
  12. php 服务器 mac地址吗,php获取服务器端mac和客户端mac的地址
  13. MATLAB安装“geoidegm2008grid.mat”数据(EGM2008模型计算大地水准面和高程异常)
  14. 单片机控制直流电机正反转
  15. 高效的睡眠——睡眠革命
  16. 以太坊源码阅读【Transaction(交易模块)】
  17. 如何构建企业TPM管理体系?
  18. 手机重装为linux,安卓手机重装系统的方法
  19. 用vlookup函数就能判断你的Excel水平处于几段
  20. (基础篇1-15)项目架构简介及环境搭建

热门文章

  1. 使用adb进行apk提取,判断的简单方法
  2. 按键精灵定时执行录制脚本
  3. 基于c语言实现的对代码的同源性检测
  4. 我们就必须承认:这个世界上,有很多问题,就是无解的
  5. android课程表的实现
  6. 大数据培训学习效果好吗
  7. linux常用命令(50个)
  8. arduino控制RFID门禁卡
  9. 用css使用html设置背景图片自适应,CSS怎么设置背景图片自适应全屏?附源码!...
  10. 软件是用计算机解决问题的过程中,计算机解决问题的过程