Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Books on keyboard detection?

Featured Replies

Hey, I'm looking for books and maby up to date documentaries about keyboard detection.

So I don't need to have an input.

 

I'm not sure if Javascript can handle it.

I have already something on keyCode and the switch statement but they arn't working anymore.

 

So any recommendations?

Maby some kind of different language I must learn for it?

JS keyCode should work fine for detecting keyboard actions. It's more likely there's a problem with your code. Post your script and explain what you're trying to do with it.

  • Author

#bar1
{
background-image:url('bar.png');
width:221px;
height:35px;
}
</style>
</head>
<body>
<script type="text/javascript">

document.getElementById("bar1").onkeydown=function(e)
e=e||event;
{
 switch(e.keyCode) {
 case 37: // left
   this.style.left = parseInt(this.style.left)-this.offsetWidth+'px';
   return false;
 case 38: // up
   this.style.top = parseInt(this.style.top)-this.offsetHeight+'px';
   return false;
 case 39: // right
   this.style.left = parseInt(this.style.left)+this.offsetWidth+'px';
 return false;
 case 40: // down
   this.style.top = parseInt(this.style.top)+this.offsetHeight+'px';
   return false ;
 }

}
</script>
<div id="bar1"></div>

This is the script I copied and done it for mine bar code but it seems it doesn't work.

<div id="bar1" style="top:0px; left:0px;"></div>

<script type="text/javascript">
document.body.onkeydown=function(e) {
var bar = document.getElementById("bar1"),
	top = parseInt(bar.style.top),
	left = parseInt(bar.style.left),
	height = bar.offsetHeight,
	width = bar.offsetWidth;
e = e || event;
switch(e.keyCode) {
	case 37: // left
		bar.style.left = left - width + 'px';
	break; 
	case 38: // up
		bar.style.top = top - height + 'px';
	break;
	case 39: // right
		bar.style.left = left + width + 'px';
	break;
	case 40: // down
		bar.style.top = top + height +'px';
	break;
}
}
</script>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.