Inércia Sensorial

2012-12-06

Powershell script to snap an app in Windows 8

Filed under: Programação — Tags: , , — inerte @ 13:52

You can not, from inside a Windows 8 application, snap it.

That doesn’t mean there is no other way 🙂

At work, we have to test our app in a snapped state, so we need a way to programmatically make it happen. We discovered that there are two keyboard shortcuts for this action. Windows Key + . (the period key) snaps to the right edge, and Windows Key + Shift + . snaps to the left edge.

So all we have to do is send these keys to the operating system. Sending the Windows Key is tricky, and not supported using only [System.Windows.Forms.SendKeys]::SendWait.

So here’s an alternative:

Download InputSimulator.dll

Run the following commands on a Powershell prompt:

1
2
[Reflection.Assembly]::LoadFile("C:\path\to\InputSimulator.dll")
[WindowsInput.InputSimulator]::SimulateModifiedKeyStroke('LWIN', 'OEM_PERIOD')

And your app will snap to the right edge. I am still researching how to snap to the left edge, it’s a more complicated call to SimulateModifiedKeyStroke, but will keep researching.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Sorry, the comment form is closed at this time.

Powered by WordPress