Using fireEvent with onKeyDown to mirror keys pressed 
Author Message
 Using fireEvent with onKeyDown to mirror keys pressed

I am trying to capture the character code of any key the
user presses in one place and trigger the correct response
elsewhere.

The way I have tried to do this is to capture the
onKeyDown event from the input element, and then use it
with fireEvent on the output element. This seems to
trigger onKeyDown on the output element, and I have put in
an alert which is showing that it is getting the correct
keyCode, but the results of the key pressed are not being
reflected in the output element.

In the test below I am using div tags, as this is what I
need to use in the end, but I've tried it with text inputs
as well, but still to no avail.

<html>

<head>
<title>Key Press Capturing Test</title>

<style>
        DIV { border: 1px black solid; }
</style>

<script language="javascript">
<!--
function mirror_keys(eventobj){
        document.getElementById('outputdiv').fireEvent
('onKeyDown',eventobj);

Quote:
}

-->
</script>

</head>

<body>
<b>Type in this div:</b>
<div id="inputdiv" contenteditable onKeyDown="mirror_keys
(window.event);">Something to test...</div>
<br />
<b>Keys pressed should be mirrored here:</b>
<div id="outputdiv" contenteditable onKeyDown="alert
(window.event.keyCode);">Something to test...</div>
</body>

</html>

Thanks in advance,
Sam.



Mon, 06 Sep 2004 22:06:07 GMT  
 Using fireEvent with onKeyDown to mirror keys pressed
fireEvent will fire the event without doing the action.

I think it would be better in this case to use the
setExpression to have a mirror object.

http://msdn.microsoft.com/library/default.asp?
url=/workshop/author/dhtml/reference/methods/setexpression.
asp

or you can also change the innerHTML/innerText attributes
http://msdn.microsoft.com/library/default.asp?
url=/workshop/author/dhtml/reference/properties/innerhtml.a
sp

Quote:
>-----Original Message-----
>I am trying to capture the character code of any key the
>user presses in one place and trigger the correct
response
>elsewhere.

>The way I have tried to do this is to capture the
>onKeyDown event from the input element, and then use it
>with fireEvent on the output element. This seems to
>trigger onKeyDown on the output element, and I have put
in
>an alert which is showing that it is getting the correct
>keyCode, but the results of the key pressed are not being
>reflected in the output element.

>In the test below I am using div tags, as this is what I
>need to use in the end, but I've tried it with text
inputs
>as well, but still to no avail.

><html>

><head>
><title>Key Press Capturing Test</title>

><style>
>    DIV { border: 1px black solid; }
></style>

><script language="javascript">
><!--
>function mirror_keys(eventobj){
>    document.getElementById('outputdiv').fireEvent
>('onKeyDown',eventobj);
>}
>-->
></script>

></head>

><body>
><b>Type in this div:</b>
><div id="inputdiv" contenteditable onKeyDown="mirror_keys
>(window.event);">Something to test...</div>
><br />
><b>Keys pressed should be mirrored here:</b>
><div id="outputdiv" contenteditable onKeyDown="alert
>(window.event.keyCode);">Something to test...</div>
></body>

></html>

>Thanks in advance,
>Sam.
>.



Tue, 07 Sep 2004 02:48:50 GMT  
 Using fireEvent with onKeyDown to mirror keys pressed

Quote:
>I think it would be better in this case to use the
>setExpression to have a mirror object.

Thanks, I have given this a go, and it works in the test,
but unfortunately it isn't really suitable for the end
application.

In the end app I have a floating toolbar window over the
main browser window, and I need it to pass the output div
on the main browser window the first key code pressed.
After the first key the window is blurred, so that's why I
only need the first key.

So there isn't actually an input div on the toolbar
window. I have got it doing alphanumeric keys by applying
the character from the key code to the text range on the
output div. However, it's the keys such as backspace and
delete that I need to get working now.

Any ideas?

Thanks,
Sam.



Tue, 07 Sep 2004 18:42:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. key press - arrow keys?

2. OnKeyDown-event: How to cancel the default action of function key's in Internet Explorer

3. BUG: key events. onkeydown vs onkeypress versus documentation

4. OnKeyDown-event: How to cancel the default action of function key's in Internet Explorer

5. OnKeyDown-event: How to cancel the default action of function key's in Internet Explorer

6. Catch ENTER key OnKeyDown Event

7. Detecting shift key being pressed in IE5/5.5?

8. anyway to detect the tab key press ?

9. How do I catch Enter-key presses in both IE/Netscape

10. can you simulate the pressing of the tab key through code

11. pressing the enter key

12. Detect mouse movement or key press in VBS ?

 

 
Powered by phpBB® Forum Software