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

  • SEARCH
  • Home
  • 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 6154865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:19:59+00:00 2026-05-23T20:19:59+00:00

I need to determine what caused a focus event. Ideally, I want to differentiate

  • 0

I need to determine what caused a focus event.

Ideally, I want to differentiate between a click, a tab/keyboard input, and a manual (via code) trigger.

How can I do this?

I’m looking at the event object, but I’m not seeing anything too useful.

  • 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-23T20:20:00+00:00Added an answer on May 23, 2026 at 8:20 pm

    If the focus comes from a $x.focus() call, then the event won’t have an originalEvent property because there was no event from the browser so:

    if(ev.hasOwnProperty('originalEvent')) {
        // Focus event was manually triggered.
    }
    

    To differentiate between keyboard and mouse based focus events, you could try binding a keydown handler to everything else to detect a Tab or Shift-Tab but that would be a gross hack and probably not reliable; for example, on an iPad, you don’t hit Tab to move to the next field, you hit Next or Previous in the popup keyboard to move around and those may not register as key presses at all.

    There’s a similar question about click events that might be of interest as well:

    In jQuery, how can I tell between a programmatic and user click?

    As you note in the comments, you could trap click events to detect a mouse-based focus change and set a flag somewhere to remember it. Then you’d have this:

    1. If there is no originalEvent in the jQuery event then the focus change was triggered manually (i.e. $x.focus() or similar).
    2. If the click handler flag is set then the focus change came from a mouse action.
    3. Otherwise the focus change came from a keyboard event.

    You’d have to be careful that your click and focus events came in the right order and you’d need to make sure the flag was cleared when you’re done with it. This might not be bullet proof but maybe it doesn’t need to be.

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

Sidebar

Related Questions

I need to determine if a given selection is in between a start line
My winform application is launched by another application (the parent), I need determine the
I need to determine in 80% if a file is binary or text, is
I need to determine file type (i.e., MimeType) of stored data in the SQL
I need to determine whether or not two sets contains exactly the same elements.
I need to determine the clients .NET framework version in my web application. I'm
I need to determine whether a selected UIColor (picked by the user) is dark
We need to determine a quick way for our web application deployed in a
I need to Determine the serial port name connected to other machine using c#.
I need to determine whether an HTTP request was an HTTP/1.0 or an HTTP/1.1

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.