2

I want my script to pretend like it is actually typing, so that the rest of my scripts that listen for changes work. Just trying to do some automation here.

Anyway,

How would one get javascript / jquery to prentend to type, say a space?

I tried this:

typeBox.val(" ");
typeBox.trigger('keypress');

But it doesn't work?

3 Answers 3

1

You need to pass the event into the trigger call

var e = jQuery.Event("keypress");
e.which = e.charCode = e.keyCode = 32;
typeBox.trigger(e);

Read the docs here:

http://api.jquery.com/trigger/

http://api.jquery.com/category/events/event-object/

Sign up to request clarification or add additional context in comments.

Comments

0
<script type="text/javascript">
function textsizer(e){
var evtobj=window.event? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode
var actualkey=String.fromCharCode(unicode)
if (actualkey=="a")
document.body.style.fontSize="120%"
if (actualkey=="z")
document.body.style.fontSize="100%"
}
document.onkeypress=textsizer
</script>

Comments

0

have a look at jQuery.trigger and jQuery.Event

var e = jQuery.Event("keydown");
e.which =//someKeyValue **
typeBox.trigger('keypress', e);

**someValue

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.