Page 1 of 1

How would I... ?

Posted: Wed May 18, 2005 3:05 pm
by Jr
Just curious if anyone knows how I would make text print out when I hold a spacific key and remove it when I release.

Posted: Wed May 18, 2005 3:41 pm
by phpScott
i think it is onKeyPress() or something very similar

Posted: Thu May 19, 2005 9:24 am
by n00b Saibot
onKeyDown() & onKeyUp() ;)

Posted: Thu May 19, 2005 11:51 am
by Jr
Ok I got this to work so far except...

- how to make it work when a spacific key is pressed
- and how to make it so it comes up in the right spot when I scroll down on the page
(and doesn't pop-up off the screen where I can't see it)

Is that something with the Y direction maybe? (I really dont know) Please help...

Code: Select all

<script language=&quote;Javascript&quote;>
<!--
function toggleDiv(id,flagit) {
	if (flagit==&quote;1&quote;)
	{
		if (document.layers) document.layers&#1111;''+id+''].visibility = &quote;show&quote;
		else if (document.all) document.all&#1111;''+id+''].style.visibility = &quote;visible&quote;
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = &quote;visible&quote;
	}
	if (flagit==&quote;0&quote;)
	{
		if (document.layers) document.layers&#1111;''+id+''].visibility = &quote;hide&quote;
		else if (document.all) document.all&#1111;''+id+''].style.visibility = &quote;hidden&quote;
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = &quote;hidden&quote;
	}
}



function ViewData(user,ValueShow)
{
if(user.style.visibility==ValueShow)return true

	var mousex = window.event.x;		// mouse location capture event
	var mousey = window.event.y;		// mouse location capture event
	user.style.visibility = ValueShow;	// show or hide respective Example
	user.style.left = mousex - 50;		// place popup at the mouse X (left) location
	user.style.top = mousey;			// place popup at the mouse Y (top) location

}
//-->
</script>


<style>
	#example1 {
		position:absolute;
		width:150px;
		height:100px;
		color:blue;
		text-align:center;
		visibility:hidden;
		z-index:10;
	}
</style>

</head>
<body onKeyDown=&quote;ViewData(example1,'visible')&quote; onKeyUp=&quote;ViewData(example1,'hidden')&quote;>

<div id=&quote;example1&quote;>
This is the menu
</div>

</body>

Posted: Thu May 19, 2005 12:50 pm
by Burrito
You're going to need an event handler (easy with IE, not so easy with FF).

then check against the event to see which key was pressed (using the key code) and then do stuff accordingly.

ex for IE:

Code: Select all

function checkEvt(evt){
	if(evt.keyCode == 13 && evt.ctrlKey){
		//do stuff		
	}
}
<span onClick=&quote;checkEvt(event)&quote;>click me</span>