## 2012-12-06

### Powershell script to snap an app in Windows 8

Filed under: ProgramaÃ§Ã£o — Tags: , , — inerte @ 13:52

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:

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.