{"id":21033200,"url":"https://github.com/josephuspaye/activate-previous-window","last_synced_at":"2026-05-08T03:42:23.917Z","repository":{"id":116941434,"uuid":"278291510","full_name":"JosephusPaye/activate-previous-window","owner":"JosephusPaye","description":"↩ Programmatically switch to the previously active window on Windows","archived":false,"fork":false,"pushed_at":"2020-07-09T10:59:11.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-18T13:02:39.293Z","etag":null,"topics":["createweekly","nodejs","windows"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JosephusPaye.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-09T07:14:53.000Z","updated_at":"2020-11-18T08:02:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"f02d43be-22dd-4b5b-99d5-bef4f39d7353","html_url":"https://github.com/JosephusPaye/activate-previous-window","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JosephusPaye/activate-previous-window","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephusPaye%2Factivate-previous-window","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephusPaye%2Factivate-previous-window/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephusPaye%2Factivate-previous-window/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephusPaye%2Factivate-previous-window/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JosephusPaye","download_url":"https://codeload.github.com/JosephusPaye/activate-previous-window/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosephusPaye%2Factivate-previous-window/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260252543,"owners_count":22981286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["createweekly","nodejs","windows"],"created_at":"2024-11-19T12:53:05.236Z","updated_at":"2025-10-26T19:48:28.513Z","avatar_url":"https://github.com/JosephusPaye.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Activate Previous Window\n\nA native Node.js module for switching to the previously active window on Windows. It programatically replicates what happens when you quickly press and release \u003ckbd\u003eAlt\u003c/kbd\u003e+\u003ckbd\u003eTab\u003c/kbd\u003e.\n\n## Installation\n\n```\nnpm install JosephusPaye/activate-previous-window --save\n```\n\n## Usage\n\n```js\nconst { activatePreviousWindow, activatePreviousWindowInChildProcess } = require('activate-previous-window');\n\n// Activate the previous window\nactivatePreviousWindow();\n\n// Same as above, but run the activation using the standalone binary in a child process.\n// Works in environments like Electron, where the Node process is not the same as the main window's.\nactivatePreviousWindowInChildProcess();\n```\n\n## How it works\n\nThe module follows the [approach taken here](https://stackoverflow.com/a/13660585). That means it:\n\n- Enumerates top-level windows in z-order using [EnumWindows()](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumwindows).\n- Chooses the second window that is visible and has a non-empty title. This is assumes that the topmost (first) window in z-order is the currently active window, and the second window below that is the previously active window.\n- Switches to the chosen window using [SetForegroundWindow()](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow).\n\n## Alternative approaches\n\nI tried a few other approaches that didn't work:\n\n- Simulating \u003ckdb\u003eAlt+Tab\u003c/kbd\u003e using [SendInput()](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput). This led to a flicker where the Alt Tab switcher was visible briefly before the active window was switched.\n- Using [GetWindow()](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindow) to get the previous window in Z-order, instead of `EnumWindows()`. This required getting the handle of the current active window, and had problems redirecting focus when switching. Using `SetForegroundWindow()`, the window switched to would come to the top, but won't have keyboard focus.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephuspaye%2Factivate-previous-window","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosephuspaye%2Factivate-previous-window","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephuspaye%2Factivate-previous-window/lists"}