Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 839637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:29:50+00:00 2026-05-15T05:29:50+00:00

I am trying to programmatically fire a key event to go left in a

  • 0

I am trying to programmatically fire a key event to go left in a text box, but not having any luck.

The input element has focus and the cursor is at the end. I’m trying to get the cursor to move left one step – before the letter “F” *programmatically by firing a Keyboard event (keydown/keyup/keypress) with the corresponding keystroke ← or → targeted at the input box.

ABCDEF|

Here’s the code so far:

HTML

<input id="a" type="text" />

Javascript

var keyEvent = document.createEvent("KeyboardEvent");

var keyLocation = '0x00';
var keyIdentifier = "Left";

keyEvent.initKeyboardEvent("keypress",
                        true,
                        true,
                        window,
                        keyIdentifier,
                        keyLocation,
                        false);

$("a").dispatchEvent(keyEvent);

Saved a quick demo on jsfiddle if you want to see the whole code – http://jsfiddle.net/Vsafv/

I am not interested in making this cross-browser (just get it working in Chrome).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:29:51+00:00Added an answer on May 15, 2026 at 5:29 am
    e = jQuery.Event("keydown"); // define this once in global scope
    e.which = 37; // Some key value
    $("input").trigger(e);
    

    where “input” is your textarea

    37 – left
    38 – up
    39 – right
    40 – down

    So when you record your “events” you record the values for the keys pressed.
    I’m sure you already figured out a way to do this but just in case, here’s an idea of how i would tackle it:

    var keysPressed = new Array(); // somewhere in the global scope
    $("input").keydown(function (e) {
        keysPressed.push(e.which); //adding values to the end of array
    });
    

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to programmatically start explorer.exe but I'm not having any luck. This is
I'm trying to manually fire a MouseLeftButtonDown event on a WPF control programmatically, as
I'm trying to programmatically select a substring of text inside of an input text
I am trying to programmatically skin a PopUpButton control in Flex Builder, but having
I'm trying to programmatically add a series to a Dundas TreeMap but I'm getting
I'm trying to programmatically add an identity column to a table Employees. Not sure
Im trying to simulate a touch on as UIWebView, how can I programmatically fire
I'm trying to programmatically replace <? with <?php in a bunch of file, but
I'm trying to programmatically create the custom horizontal menu for my custom module, but
I'm trying to programmatically call an event to launch an application in Windows Phone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.