Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1170
  • Last Modified:

send arrow keystroke in c# or javascript ( or vb .net ) to IE browser window

Is there any way I can send a keystroke to a browser from Javascript or .net - C#? I am looking for forward arrow key in paricular. It only needs to work in IE, and actually only on the local intranet.

...I expect there may not be a Javascript solution, but maybe I can track an hidden element on the page - and when it's changed I send the key?

I might also accept a solution in VB, but C# would be much better.
0
CallConnection
Asked:
CallConnection
  • 4
  • 3
  • 2
1 Solution
 
renjurdevanCommented:
you can capture onkeypress, onkeydown events of body tag

<body onkeypress="function_Call()" onkeydown="function_Call()">



function function_Call()
{
// set a flag into hidden field
}

you can get onclick event also for mouse click

Regards
Renju
0
 
REA_ANDREWCommented:
you can access the keyCode

function getKey(e) {
var e = e || window.event;
alert(e.keyCode);
}

<html>
<head>
<title></title>
<script type="text/javascript">
function getKey(e) {
var e = e || window.event;
alert(e.keyCode);
}
</script>
</head>
<body onkeydown="getKey(event);">

</body>
</html>
0
 
CallConnectionAuthor Commented:
Guys, that's ok, but I am looking to SEND a keystroke from the web appication (not GET what the user pressed)... [This to resolve a strange IE glitch I have come across.]

That's why I wondered if C# can actually do it?.. But thinking about it C# would probably only cater for server-side events so that sound unlikely... Still I thought I'd check with you to make sure.
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
REA_ANDREWCommented:
what would you like to achieve with sending this arow key? To scroll the window or something?

Andrew
0
 
CallConnectionAuthor Commented:
Basically I was trying to save some time to help users not have to re-enter the same information in the second box (similar to simplified eg below).

But I have a strange IE bug - the cursor is set to a correct control on the page, but it's not visible...

But I can tell that it is the right control because I can pick it up with onFocus event and it also appears in the right box when you press any key.

Please have a look at this:

<html>
<body>
<script>
function d()
{
document.getElementById('id2').value = document.getElementById('id1').value;
}
</script>
<input id="id1" type="text" value="1234" onblur="d()"></input>
<input id="id2" type="text" value="1234"></input>
</body>
</html>

Any thoughts?
0
 
renjurdevanCommented:
<html>
function d()
{
document.getElementById('id2').value = document.getElementById('id1').value;
}
</script>
</head>
<body >
<input id="id1" type="text" value="1234" onblur="d()"></input>
<input id="id2" type="text" value="1234"></input>
</body>
</html>

For me it works fine!! Try to put your script well outside body tag like what i did

Regards
Renju
0
 
renjurdevanCommented:

renjurdevan:
<html>
<head>
<script>
function d()
{
document.getElementById('id2').value = document.getElementById('id1').value;
}
</script>
</head>
<body >
<input id="id1" type="text" value="1234" onblur="d()"></input>
<input id="id2" type="text" value="1234"></input>
</body>
</html>

0
 
CallConnectionAuthor Commented:
I see what you mean - the above works when users CLICK the second box, but as far as I can see it does not work (in IE 6 / IE 7) when users change the text in the first box and press tab key to get to the second box. The cursor is invisible until you press another key.... Hence the question above --- or can you see another way to fix this?

(By the way I am using onblur events in both textboxes for other purposes...)
0
 
CallConnectionAuthor Commented:
I think have fixed this by using onfocus="this.select()"... which means the whole field is selected but at least user knows where he is... Thanks guys!!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now