由网友(不忘初心.)分享简介:我要检测角位移+右箭头+ P的一个问题。结果我使用的角度1.2.3我没有问题,只检测右箭头+ P,但换挡时进入游戏的东西刹车问题是热的检测情况时,3键是pressed:SHIFT +右箭头键+ P 下面是一个工作的例子 plunker VAR应用= angular.module('keyboardDemo',[]...
我要检测角位移+右箭头+ P的一个问题。结果我使用的角度1.2.3我没有问题,只检测右箭头+ P,但换挡时进入游戏的东西刹车
问题是热的检测情况时,3键是pressed:SHIFT +右箭头键+ P
下面是一个工作的例子 plunker
VAR应用= angular.module('keyboardDemo',[]);app.controller('MainCtrl',函数($范围,$超时){ / ** * 39(右箭头) * 80(p)的 * / VAR地图= {39:假的,80:假}; $ scope.onKeyUp =函数(事件){ 如果(图[39]和放大器;&放大器;图[80]){ $ scope.data.message1 =P + RIGHT pressed!; $超时(函数(){ $ scope.data.message1 =''; },1000); } 如果(event.shiftKey&安培;&放大器;图[39]和放大器;&放大器;图[80]){ $ scope.data.message2 =SHIFT + P + RIGHT pressed!; $超时(函数(){ $ scope.data.message2 =''; },1000); } VAR键code = getKeyboardEvent code(事件); 如果(在地图键code){ clearKey code(键code); } }; $ scope.onKeyDown =函数(事件){ VAR键code = getKeyboardEvent code(事件); 如果(在地图键code){ 图[关键code] =真; } } VAR getKeyboardEvent code =功能(事件){ 返回parseInt函数((window.event event.key code:event.which)); }; 功能clearKey code(code){ 图[code] = FALSE; } $ scope.data = { MESSAGE1':'', 消息2':'' };});
解决方案
正如评论说。您code实际效果很好。在MacOS使用Chrome,当我preSSSHIFT + P +右箭头并释放键,我看到两个消息。
I have a problem to detect shift + right arrow + p in angular. I am using angular 1.2.3 I have no problem to detect only right arrow + p but when the shift comes into game something brakes
The question is hot to detect situation when 3 keys are pressed: SHIFT + RIGHT ARROW + P
Here is a working example on plunker
var app = angular.module('keyboardDemo', []);
app.controller('MainCtrl', function($scope, $timeout) {
/**
* 39 (right arrow)
* 80 (p)
*/
var map = {39: false, 80: false};
$scope.onKeyUp = function(event){
if (map[39] && map[80]) {
$scope.data.message1 = "P + RIGHT pressed!";
$timeout(function(){
$scope.data.message1 = '';
}, 1000);
}
if (event.shiftKey && map[39] && map[80]) {
$scope.data.message2 = "SHIFT + P + RIGHT pressed!";
$timeout(function(){
$scope.data.message2 = '';
}, 1000);
}
var keyCode = getKeyboardEventCode(event);
if (keyCode in map) {
clearKeyCode(keyCode);
}
};
$scope.onKeyDown = function(event){
var keyCode = getKeyboardEventCode(event);
if (keyCode in map) {
map[keyCode] = true;
}
}
var getKeyboardEventCode = function (event) {
return parseInt((window.event ? event.keyCode : event.which));
};
function clearKeyCode(code){
map[code] = false;
}
$scope.data = {
'message1': '',
'message2': ''
};
});
解决方案
As said in the comment. Your code works actually well . Using chrome on macOS, when i press "SHIFT + P + RIGHT ARROW" and release the keys i see both messages.
相关推荐
最新文章