Logo

js监听键盘事件

photo

2022年04月29日

		document.addEventListener('keydown', function(e){
			    if (e.keyCode == 86 && e.ctrlKey) {
			        alert("你按下了ctrl+V");
			    }
			    if (e.keyCode == 86 && e.altKey) {
			        alert("你按下了alt+V");
			    }
			    if (e.keyCode == 86 && e.shiftKey) {
			        alert("你按下了shift+V");
			    }
			     if (e.keyCode == 83 && e.ctrlKey){
					 alert('saved1');
			    	e.preventDefault();
			    	alert('saved');
			     }
			    if (e.keyCode == 83 && e.ctrlKey && e.shiftKey) {
			        alert("你按下了ctrl+shift+S");
			    }
			    if (e.keyCode == 13&&e.ctrlKey) {
			        alert("你按下了ctrl+回车");
			        return;
			    }
			    if (e.keyCode == 13) {
			        alert("你按下了回车");
			    }
		});
			keyCode 65 = a A
			keyCode 66 = b B
			keyCode 67 = c C
			keyCode 68 = d D
			keyCode 69 = e E EuroSign
			keyCode 70 = f F
			keyCode 71 = g G
			keyCode 72 = h H
			keyCode 73 = i I
			keyCode 74 = j J
			keyCode 75 = k K
			keyCode 76 = l L
			keyCode 77 = m M mu
			keyCode 78 = n N
			keyCode 79 = o O
			keyCode 80 = p P		
			keyCode 81 = q Q at		
			keyCode 82 = r R	
			keyCode 83 = s S
			keyCode 84 = t T	
			keyCode 85 = u U	
			keyCode 86 = v V
			keyCode 87 = w W
			keyCode 88 = x X
			keyCode 89 = y Y
			keyCode 90 = z Z
			
			//第一行
			keyCode 27 = Esc
			keyCode 112 = F1 
			keyCode 113 = F2 
			keyCode 114 = F3 
			keyCode 115 = F4 
			keyCode 116 = F5 
			keyCode 117 = F6 
			keyCode 118 = F7 
			keyCode 119 = F8 
			keyCode 110 = F9 
			keyCode 121 = F10
			keyCode 122 = F11 
			keyCode 123 = F12 
			keycode 42 = Print
			keycode 137 = Scroll_Lock
			keycode 19 = Pause
			
			//第二行
			keycode `~ = 192
			keycode 48 = 0 )
			keycode 49 = 1 !
			keycode 50 = 2 @
			keycode 51 = 3 #
			keycode 52 = 4 $
			keycode 53 = 5 %
			keycode 54 = 6 ^
			keycode 55 = 7 &
			keycode 56 = 8 *
			keycode 57 = 9 (
			keycode 187 = =+
			keycode 189 = -_
			keycode 8 = BackSpace
			
			//其他特殊符号
			keycode 9 = Tab
			keycode 20 = Caps_Lock(大写锁定)
			e.shiftKey
			e.ctrlKey
			e.altKey
			keycode 32 = Space(空格键)
			keycode 13 = Enter(回车)
			keycode 219 = [{
			keycode 220 = \|
			keycode 221 = ]}
			keycode 222 = '"
			keycode 188 = ,<
			keycode 190 = .>
			keycode 191 = /?
			keycode 45 = Insert
			keycode 46 = Delete
			keycode 36 = Home
			keycode 35 = End
			keycode 33 = Page Up
			keycode 34 = Page Down
			keycode 37	= Left(左箭头)
			keycode 38 = Up(上箭头)
			keycode 39 = Right(右箭头)
			keycode 40 =	Down(下箭头)

			数字键盘
			keycode 96 = 0 (数字0)
			keycode 97 = 1 (数字1)
			keycode 98 = 2 (数字2)
			keycode 99 = 3 (数字3)
			keycode 100 = 4 (数字4)
			keycode 101 = 5 (数字5)
			keycode 102 = 6 (数字6)
			keycode 103 = 7 (数字7)
			keycode 104 = 8 (数字8)
			keycode 105 = 9 (数字9)
			keycode 106 = *  
			keycode 107 = +
			keycode 108 = Enter
			keycode 109 = -
			keycode 110 = .
			keycode 111 = /
所有附件
该文章没有附件.
本文为原创文章,请注意保留出处!

热门文章

修复群晖Synology Drive client右键菜单缺失问题 本教程主要解决windows10右键菜单中没有SynologyDrive菜单的问题,整体思路是找到...修复群晖SynologyDriveclient右键菜单缺失问题 作者:Pastore Antonio
1812 浏览量
docker如何查看一个镜像内部的目录结构及其内部都有哪些文件 前言:有时候我们会在docker上下载一个镜像,或者是上传一个镜像到docker上,甚至有时候就是在...docker如何查看一个镜像内部的目录结构及其内部都有哪些文件 作者:Pastore Antonio
1791 浏览量
configure: error: Package requirements (oniguruma) were not met configure:error:Packagerequirements(oniguruma)...configure:error:Packagerequirements(oniguruma)werenotmet 作者:Pastore Antonio
1530 浏览量
Adobe Acrobat Pro 激活 这里记录了一些AdobeAcrobat的激活教程和组件。浏览量:1,683 作者:Pastore Antonio
1528 浏览量
追寻日出,找回自己 为什么我要去追寻日出?其实我是一个很懒的人,每次都起不来,直到有一次我在租房中睡到了大天亮,阳光照...追寻日出,找回自己 作者:Pastore Antonio
1506 浏览量