GithubHelp home page GithubHelp logo

omygithub / wasp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mavaddat/wasp

0.0 2.0 0.0 59 KB

Windows Automation Snapin for PowerShell

License: Mozilla Public License 2.0

C# 99.49% PowerShell 0.51%

wasp's Introduction

WASP

WASP is a PowerShell snapin for Windows Automation tasks like selecting windows and controls and sending mouse and keyboard events. WASP has automation cmdlets like Select-Window, Select-Control, Send-Keys, Send-Click, Get-WindowPosition, Set-WindowPosition, Set-WindowActive, Remove-Window ... etc.

Its goal is to enable Windows GUI Automation scripting from inside PowerShell without resorting to specialized scripting tools.

Just to be clear, don't expect any "click to record" functionality ... but do expect to be able to automatically tile windows, send mouse clicks and keystrokes, and in general, automate those tasks that you would normally not be able to do from a console.

Some Usage Examples

Author's standard demo:

{{

Open a couple windows

notepad.exe explorer.exe

list the windows

Select-Window | ft –auto

Activate Notepad

Select-Window notepad* | Set-WindowActive

Close Explorer

Select-Window explorer | Select -First 1 | Remove-WIndow

Run a few more copies of notepad

notepad; notepad; notepad; notepad;

Move them around so we can see them all ... (Note the use of foreach with the incrementation)

$i = 1;$t = 100; Select-Window notepad | ForEach { Set-WindowPosition -X 20 -Y (($i++)*$t) -Window $_ }

Put some text into them ...

Select-Window notepad | Send-Keys "this is a test"

Close the first notepad window by pressing ALT+F4, and pressing Alt+N

In this case, you don't have to worry about shifting focus to the popup because it's modal

THE PROBLEM with sending keys like that is:

if there is no confirmation dialog because the file is unchanged, the Alt+N still gets sent

Select-Window notepad | Select -First 1 | Send-Keys "%{F4}%n"

Close the next notepad window ...

By asking nicely (Remove-Window) and then hitting "n" for "Don't Save"

If there are no popups, Select-ChldWindow returns nothing, and that's the end of it

Select-Window notepad | Select -First 1 | Remove-Window -Passthru | Select-ChildWindow | Send-Keys "n"

Close the next notepad window the hard way

Just to show off that our "Window" objects have a ProcessID and can be piped to kill

Select-Window notepad | Select -First 1 | kill

A different way to confirm Don't Save (use CLICK instead of keyboard)

Notice how I dive in through several layers of Select-Control to find the button?

This can only work experimentally:

use SPY++, or run the line repeatedly, adding "|Select-Control" until you see the one you want

Select-Window notepad | Select -First 1 | Remove-Window -Passthru | Select-childwindow | select-control| select-control| select-control -title "Do&n't Save" | Send-Click

But now we have the new -Recurse parameter, so it's easy. Just find the window you want and ...

Select-Window notepad | Select -First 1 | Remove-Window -Passthru | Select-childwindow | select-control -title "Do&n't Save" -recurse | Send-Click }}

Author's favorite use: re-dock all visual studio tool windows

{{

NOTE: 0, 0 is the resize corner, so you need to specify X,Y coordinates for the click:

Select-Window devenv | Select-ChildWindow | Send-Click 10 10 -Double }}

Automation cmdlets

  • Select-Window - Pick windows by process name or window caption (with wildcard support)
  • Select-ChildWindow - Pick all owned windows of another window (e.g., dialogs, tool windows)
  • Select-Control - Pick controls (children) of a specific window, by class and/or name and/or index (with wildcard support) -- NOTE: the "Window" can be specified as "-Window 0" to get all parentless windows, which includes windows, dialogs, tooltips, etc... With -Window 0 this returns a true superset of the Select-Window output.
  • Send-Click - send mouse clicks (any button, with any modifier keys)
  • Send-Keys - Windows.Forms.SendKeys lets you send keys ... try this: {{Select-Window notepad | Send-Keys "%(ea)Testing{Enter}{F5}"}} (and for extra fun, try it with multiple notepad windows open).
  • Set-WindowActive - Simply activates the window
  • Set-WindowPosition - Set any one of (or all of) top, left, width, height on a window ... or maximize/minimize/restore
  • Get-WindowPosition - Get the position (kind-of redundant, actually, since the Window object has it's position as a property)
  • Remove-Window - Closes the specified window

wasp's People

Contributors

mavaddat avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.