forcefocus

Node module that allows you to steal focus from other windows in Windows.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
forcefocus
80171.1.04 years ago6 years agoMinified + gzip package size for forcefocus in KB

Readme

forcefocus
Node module that allows you to steal focus from other windows in Windows.

npm NpmVersion NpmLicense AppVeyor branch Travis (.org) branch
Microsoft changed the implementation of SetFocus().aspx) to only allow an app to grant focus to other windows if it currenly holds the focus. If an app that does not have the focus tries to take it, the taskbar will just flash rather than focusing the window. These changes was probably done to improve the user experience, so users would not be disturbed by the focused application suddenly switching.
This module circumvents the restrictions in SetFocus() and allows any window to steal the focus.
It reuses the Electron built-in focus on other platforms.

Installation

Install forcefocus by running:
$ npm install --save forcefocus

Native binaries for win, mac and linux are prebuilt and downloaded when the module is installed.

Documentation

forcefocus.focusWindow(window)

Kind: static method of forcefocus
Summary: Force focus on a Window
Access: public
| Param | Type | Description | | --- | --- | --- | | window | BrowserWindow | Window to focus |
Example
const forceFocus = require('forcefocus');
const currentWindow = require('electron').remote.getCurrentWindow();

forceFocus.focusWindow(currentWindow);

Example application

Example application gif
An example application is located in the /example/ dir, start it by running:
$ npm run example

Contribute

Feel free to contribute to this module.
Before submitting a PR, please make sure that the linter runs without any warning:
$ npm run lint

License

The project is licensed under the Apache 2.0 license.