---
title: "Ctrl nedtryckt?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/javascript/128150-ctrl-nedtryckt"
topic: "JavaScript"
topic_url: "https://www.webforum.nu/amne/javascript"
author: "Boorg"
published: "2005-05-13T07:56:29.000Z"
updated: "2005-05-13T09:52:23.000Z"
replies: 5
views: 407
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/javascript/128150-ctrl-nedtryckt"
---

# Ctrl nedtryckt?

## #1 — Boorg, 2005-05-13T07:56Z

Finns det något sätt att se ifall någon tangent är nedtryckt. T.ex Ctrl?

Permalänk: https://www.webforum.nu/p/128150

## #2 — Web-Tor, 2005-05-13T08:02Z

[Sets or retrieves the Unicode key code associated with the key that caused the event.](http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/keycode.asp?frame=true)

[Sets or retrieves the state of the CTRL key.](http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/ctrlkey.asp?frame=true)

Permalänk: https://www.webforum.nu/p/1608939

## #3 — Boorg, 2005-05-13T08:05Z

Tackar... Hittade tillcohmed ett litet script här inne efter lite intensift sökande  :r  

```
<script type="text/javascript">
<!--

document.onkeydown = function(){
	if(event.keyCode==16)
		window.open("foo.html","","height=300,width=300");
};

//-->
</script>
```

Permalänk: https://www.webforum.nu/p/1608941

## #4 — Boorg, 2005-05-13T08:32Z

> **Web-Tor skrev:**
>
> [Sets or retrieves the Unicode key code associated with the key that caused the event.](http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/keycode.asp?frame=true)
> 
> [Sets or retrieves the state of the CTRL key.](http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/ctrlkey.asp?frame=true)

Hmmmm... hur andvädner man detta då?
Är ute lite mer efter ifall det finns något sätt att hålla reda på om man håller nere tangenten utan att ladda om sidan...

EDIT: Det blir detta sättet ändå...

Permalänk: https://www.webforum.nu/p/1608955

## #5 — nitro2k01, 2005-05-13T08:56Z

Hej! Titta på detta exempel, det gör nog precis det du vill!

```
<script>
var ctrlKey=altKey=shiftKey=false;
document.onkeyup=function(e){
	var ev = e || window.event;
	ctrlKey = ev.ctrlKey;
	altKey = ev.altKey;
	shiftKey = ev.shiftKey;
}

function showModifiers(){
	alert(
	"Ctrl: " + ctrlKey + "\n" + 
	"Alt: " + altKey + "\n" + 
	"Shift: " + shiftKey + "\n"
	);
}
</script>

<body>
<input type="button" onclick="showModifiers();" value="Visa!">
</body>
```

Permalänk: https://www.webforum.nu/p/1608965

## #6 — Boorg, 2005-05-13T09:52Z

Tackar! Det är till stor hjälp  :)  :bire

Permalänk: https://www.webforum.nu/p/1609001

---

Tråden på webben: https://www.webforum.nu/amne/javascript/128150-ctrl-nedtryckt
