Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/robinwassen/forcefocus

Node module that allows you to steal focus from other windows in Windows.
https://github.com/robinwassen/forcefocus

electron nodejs

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

forcefocus
=========

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

[![npm](https://img.shields.io/npm/dw/forcefocus.svg)](https://npmjs.com/package/forcefocus)
[![NpmVersion](https://img.shields.io/npm/v/forcefocus.svg)](https://npmjs.com/package/forcefocus)
[![NpmLicense](https://img.shields.io/npm/l/forcefocus.svg)](https://npmjs.com/package/forcefocus)
[![AppVeyor branch](https://img.shields.io/appveyor/ci/robinwassen/forcefocus/master.svg?logo=appveyor)](https://ci.appveyor.com/project/robinwassen/forcefocus)
[![Travis (.org) branch](https://img.shields.io/travis/robinwassen/forcefocus/master.svg?logo=travis)](https://travis-ci.org/robinwassen/forcefocus)

Microsoft changed the implementation of [SetFocus()](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646312(v=vs.85).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:

```sh
$ 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](#module_forcefocus)
**Summary**: Force focus on a Window
**Access**: public

| Param | Type | Description |
| --- | --- | --- |
| window | BrowserWindow | Window to focus |

**Example**
```js
const forceFocus = require('forcefocus');
const currentWindow = require('electron').remote.getCurrentWindow();

forceFocus.focusWindow(currentWindow);
```

Example application
-------------

![Example application gif](./media/forcefocus-example.gif)

An example application is located in the `/example/` dir, start it by running:

```sh
$ 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:

```sh
$ npm run lint
```

License
-------

The project is licensed under the Apache 2.0 license.