Js中获取键盘的事件
使用方法:
<script type="text/javascript" language=JavaScript charset="UTF-8">
document.onkeydown=function(event){
var e = event || window.event || arguments.callee.caller.arguments[];
if(e && e.keyCode==){ // 按 Esc
//要做的事情
}
if(e && e.keyCode==){ // 按 F2
//要做的事情
}
if(e && e.keyCode==){ // enter 键
//要做的事情
}
};
</script>
只要你定义了这些键的动作,你在浏览器里按下这些键就会响应,兼容目前所有浏览器。
参考目录:
js 里面的键盘事件经常用到,所以收集了键盘事件对应的键码来分享下:
keyCode = BackSpace BackSpace
keyCode = Tab Tab
keyCode = Clear
keyCode = Enter
keyCode = Shift_L
keyCode = Control_L
keyCode = Alt_L
keyCode = Pause
keyCode = Caps_Lock
keyCode = Escape Escape
keyCode = space
keyCode = Prior
keyCode = Next
keyCode = End
keyCode = Home
keyCode = Left
keyCode = Up
keyCode = Right
keyCode = Down
keyCode = Select
keyCode = Print
keyCode = Execute
keyCode = Insert
keyCode = Delete
keyCode = Help
keyCode = equal braceright
keyCode = exclam onesuperior
keyCode = quotedbl twosuperior
keyCode = section threesuperior
keyCode = dollar
keyCode = percent
keyCode = ampersand
keyCode = slash braceleft
keyCode = parenleft bracketleft
keyCode = parenright bracketright
keyCode = a A
keyCode = b B
keyCode = c C
keyCode = d D
keyCode = e E EuroSign
keyCode = f F
keyCode = g G
keyCode = h H
keyCode = i I
keyCode = j J
keyCode = k K
keyCode = l L
keyCode = m M mu
keyCode = n N
keyCode = o O
keyCode = p P
keyCode = q Q at
keyCode = r R
keyCode = s S
keyCode = t T
keyCode = u U
keyCode = v V
keyCode = w W
keyCode = x X
keyCode = y Y
keyCode = z Z
keyCode = KP_0 KP_0
keyCode = KP_1 KP_1
keyCode = KP_2 KP_2
keyCode = KP_3 KP_3
keyCode = KP_4 KP_4
keyCode = KP_5 KP_5
keyCode = KP_6 KP_6
keyCode = KP_7 KP_7
keyCode = KP_8 KP_8
keyCode = KP_9 KP_9
keyCode = KP_Multiply KP_Multiply
keyCode = KP_Add KP_Add
keyCode = KP_Separator KP_Separator
keyCode = KP_Subtract KP_Subtract
keyCode = KP_Decimal KP_Decimal
keyCode = KP_Divide KP_Divide
keyCode = F1
keyCode = F2
keyCode = F3
keyCode = F4
keyCode = F5
keyCode = F6
keyCode = F7
keyCode = F8
keyCode = F9
keyCode = F10
keyCode = F11
keyCode = F12
keyCode = F13
keyCode = F14
keyCode = F15
keyCode = F16
keyCode = F17
keyCode = F18
keyCode = F19
keyCode = F20
keyCode = F21
keyCode = F22
keyCode = F23
keyCode = F24
keyCode = Num_Lock
keyCode = Scroll_Lock
keyCode = acute grave
keyCode = comma semicolon
keyCode = minus underscore
keyCode = period colon
keyCode = numbersign apostrophe
keyCode = plusminus hyphen macron
keyCode =
keyCode = copyright registered
keyCode = guillemotleft guillemotright
keyCode = masculine ordfeminine
keyCode = ae AE
keyCode = cent yen
keyCode = questiondown exclamdown
keyCode = onequarter onehalf threequarters
keyCode = less greater bar
keyCode = plus asterisk asciitilde
keyCode = multiply division
keyCode = acircumflex Acircumflex
keyCode = ecircumflex Ecircumflex
keyCode = icircumflex Icircumflex
keyCode = ocircumflex Ocircumflex
keyCode = ucircumflex Ucircumflex
keyCode = ntilde Ntilde
keyCode = yacute Yacute
keyCode = oslash Ooblique
keyCode = aring Aring
keyCode = ccedilla Ccedilla
keyCode = thorn THORN
keyCode = eth ETH
keyCode = diaeresis cedilla currency
keyCode = agrave Agrave atilde Atilde
keyCode = egrave Egrave
keyCode = igrave Igrave
keyCode = ograve Ograve otilde Otilde
keyCode = ugrave Ugrave
keyCode = adiaeresis Adiaeresis
keyCode = ediaeresis Ediaeresis
keyCode = idiaeresis Idiaeresis
keyCode = odiaeresis Odiaeresis
keyCode = udiaeresis Udiaeresis
keyCode = ssharp question backslash
keyCode = asciicircum degree
keyCode = sterling
keyCode = Mode_switch
使用event对象的keyCode属性判断输入的键值
eg:if(event.keyCode==)alert(“enter!”);
键值对应表
A 0X65 U 0X85
B 0X66 V 0X86
C 0X67 W 0X87
D 0X68 X 0X88
E 0X69 Y 0X89
F 0X70 Z 0X90
G 0X71 0X48
H 0X72 0X49
I 0X73 0X50
J 0X74 0X51
K 0X75 0X52
L 0X76 0X53
M 0X77 0X54
N 0X78 0X55
O 0X79 0X56
P 0X80 0X57
Q 0X81 ESC 0X1B
R 0X82 CTRL 0X11
S 0X83 SHIFT 0X10
T 0X84 ENTER 0XD
如果要使用组合键,则可以判断是否同时按下了这几个键,比如ctrl键、shift键以及alt键的组合使用就可以判断是否多按下了ctrl键、shift键以及alt键
Js中获取键盘的事件的更多相关文章
- js中获取键盘事件【转】
<script type="text/javascript" language=JavaScript charset="UTF-8"> 2 docu ...
- js中获取键盘事件
<script type="text/javascript" language=JavaScript charset="UTF-8"> docume ...
- js中获取监听键盘事件
<script type="text/javascript" language=JavaScript charset="UTF-8"> docume ...
- js如何获取键盘高度
在移动端或混合app开发中,js如何获取键盘高度,直接贴上代码吧 input是一个html input 标签 var timer = { id:null, run:function (callback ...
- js中获取 table节点各tr及td的内容方法
js中获取 table节点各tr及td的内容方法 分类: java基础2013-10-12 17:54 1055人阅读 评论(0) 收藏 举报 <table id="tb1" ...
- Java中获取键盘输入值的三种方法
Java中获取键盘输入值的三种方法 Java程序开发过程中,需要从键盘获取输入值是常有的事,但Java它偏偏就没有像c语言给我们提供的scanf(),C++给我们提供的cin()获取键盘输入值 ...
- js中获取URL中指定的查询字符串
js中获取URL中指定的搜索字符串,主要利用location对象实现,废话少说,上代码. function getSearchString(key) { // 获取URL中?之后的字符 var str ...
- js中获取css属性
直接获取 window.onload = function() { var but = document.getElementById('button'); var div = document.ge ...
- 【2017-06-27】Js中获取地址栏参数、Js中字符串截取
一.Js中获取地址栏参数 //从地址栏获取想要的参数 function GetQueryString(name) { var reg = new RegExp("(^|&)" ...
随机推荐
- 013_HDFS文件合并上传putmarge功能(类似于hadoop fs -getmerge)
场景 合并小文件,存放到HDFS上.例如,当需要分析来自许多服务器的Apache日志时,各个日志文件可能比较小,然而Hadoop更合适处理大文件,效率会更高,此时就需要合并分散的文件.如果先将所有文件 ...
- 【leetcode刷题笔记】Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- cocos2dx打飞机项目笔记四:Enemy类和EnemyLayer类
Enemy类没什么内容,就create和init方法,根据参数来创建不同的敌机,头文件代码如下: //飞机的类型 enum planeType {smallPlane, midPlane, bigPl ...
- spark总结4 算子问题总结
官网上最清晰 sc 启动spark时候就已经初始化好了 sc.textFile后 会产生一个rdd spark 的算子分为两类 一类 Transformation 转换 一类 Action 动作 ...
- Luogu-3222 [HNOI2012]射箭
几何题,二次函数,化一下式子吧 设二次函数\(y=ax^2+bx\),对于一个线段\((x,y1)\),\((x,y2)\),与他相交的条件是\(y1<=ax^2+bx<=y2\) 对于\ ...
- QPushButton 响应回车 设置默认按钮
ui.pushButton->setFocus(); //设置默认焦点 ui.pushButton->setShortcut( QKeySequence::InsertParagraphS ...
- matplotlib画子图时设置总标题
matplotlib subplots绘图时 设置总标题 :fig.suptitle(name)
- SpringBoot发布到独立的tomcat中运行
在此文基础上 Eclipse下利用Maven创建SpringBoot的Restful风格程序 spring-boot默认提供内嵌的tomcat,所以打包直接生成jar包,用java -jar命令就可以 ...
- Sublime Text3取消自动补全结束标签
点击首选项——设置-用户——在配置中增加一句:"auto_close_tags": false, 参考来源:豆瓣小组:求解Sublime Text 3怎么取消自动补全结束标签
- 解决:phantomjs helloworld.js报错: Can't open 'helloworld.js'
PhantomJS是一个无界面的,可脚本编程的WebKit浏览器引.它原生支持多种web 标准:DOM 操作,CSS选择器,JSON,Canvas 以及SVG. 当我安装好PhantomJS后,写下第 ...