views:

83

answers:

3

I have an application that requires the down arrow, or the letter s for a specific function (both down arrow and the letter "s" trigger the function in the application).

The user cannot use the keyboard so I have to make a button on screen for the user to click. The application is displayed in an HTML page and I have made other buttons with the following code:

<img src="left.jpg" name="Left" onclick="javascript:[CODE_TO_RUN];" vspace="0" width="75" height="75" hspace="0" />

This works for my other functions but I cannot get sendKey to work to simulate the down arrow or the "s" key. Does anyone know how to make a button on an HTML page that will simulate pressing the down arrow or the "s" key? Please help, thank you!

A: 

You wrote "sendKey", I only know this as a method of the windows-shell. Does this mean, that it only has to work on MSIE?

If yes, you cant usually access the shell there because of security-restrictions, but you can fire an event. Example:

//create event-object
e = document.createEventObject();
//set keycode to 115(for s)
e.setAttribute('keyCode',115);
//fire on document
document.fireEvent('onkeypress',e); 

To do similar in other browsers, you find here a tutorial: http://www.howtocreate.co.uk/tutorials/javascript/domevents

Dr.Molle
A: 

You won't be able to do this in general. Firefox can be made to fully simulate some key events with associated browser behaviour; other browsers can programmatically fire key events but will not perform the usual browser action associated with the event, such as displaying a character.

Tim Down
A: 

This might be a good workaround if I understood you question correctly:

Using jQuery animate() function to do a smooth scrolling: I have also created a div as follow:

<div id="scrollToHere">
Scroll to here
</div>

You need something to run your script. Create a button like this:

The jQuery Code will be like this:

function scrollWin(){
$('html, body').animate({
scrollTop: $("#scrollToHere").offset().top
}, 2000);
}

Resource:

http://blog.freelancer-id.com/index.php/2009/03/26/scroll-window-smoothly-in-jquery

You could make scroll "buttons" always visible!

Good luck, not sure if I understood your question, please tell me if otherwise!

Trufa