2011-06-20 8 views
5

私はC#/ WPFアプリケーションでKinect SDKのジェスチャーシステムを構築しています。私は拡大鏡のズームインジェスチャーを追加したいと思います。私は、組み込みのWindowsの拡大鏡またはその基礎となるロジックを使用することを好むでしょうが、同様の効果(マルチモニタ対応)を得る方法はあれば動作します。Windowsの拡大鏡を呼び出す

Windowsの拡大鏡のズーム機能をプログラムで呼び出すにはどうすればよいですか?

これまでのところ私が見つけた唯一のことは、プロセスを開始してWin32でボタンをクリックすることです。しかし、私がそれをするとき、私は拡大鏡ウィンドウのハンドルを呼び出すと、それは空白の空のウィンドウを引き上げています。

私はC#、Win32 APIコールの束、私が実際にそれほどよくわからないこと、そして数多くのグーグル・グーグルが知っていることの組み合わせによって、このコードを一緒にパッチしました。

private void ZoomIn() 
{ 
    // Make sure the Magnifier is running, and get its handle 
    if (Process.GetProcesses().Where(p => p.ProcessName.ToLower() == "magnify").Count() == 0) { 
     Process.Start("magnify.exe"); 
     System.Threading.Thread.Sleep(500); } 
    IntPtr handle = Process.GetProcesses().Where(p => p.ProcessName.ToLower() == "magnify").First().Handle; 

    // Figure out what size ("mode") it's in 
    WINDOWPLACEMENT placement = new WINDOWPLACEMENT(); 
    placement.length = Marshal.SizeOf(placement); 
    GetWindowPlacement(handle, ref placement); 

    // Move the Magnifier to a predetermined location so we know where to click 
    MoveWindow(handle, new Point(0, 0)); 

    // If Magnifier is in small mode, click it to put it in big mode. 
    if (placement.rcNormalPosition.Size.Width == 132) { 
     SetCursorPos(15, 15); 
     mouse_event((int)HardwareEvents.MouseLeftDown, 15, 15, 0, 0); 
     mouse_event((int)HardwareEvents.MouseLeftUp, 15, 15, 0, 0); } 

    // Click the zoom in button. Yeah, I know, hackish. Isn't Win32 awesome? 
    SetCursorPos(25, 25); 
    mouse_event((int)HardwareEvents.MouseLeftDown, 25, 25, 0, 0); 
    mouse_event((int)HardwareEvents.MouseLeftUp, 25, 25, 0, 0); 
} 
private void MoveWindow(IntPtr handle, Point point) 
{ 
    // TODO: Figure out how to look up the target window's size 
    SetWindowPos(handle, new IntPtr((int)SpecialWindowHandles.HWND_TOP), (int)point.X, (int)point.Y, 500, 500, SetWindowPosFlags.ShowWindow); 
} 

private struct WINDOWPLACEMENT { 
    public int length; 
    public int flags; 
    public int showCmd; 
    public System.Drawing.Point ptMinPosition; 
    public System.Drawing.Point ptMaxPosition; 
    public System.Drawing.Rectangle rcNormalPosition; } 

[DllImport("user32.dll")] 
static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndl); 

[DllImport("user32.dll")] 
static extern bool SetCursorPos(int X, int Y); 


public static class HardwareEvents 
{ 
    public static int MouseMove = 0x0001; 
    public static int MouseLeftDown = 0x0002, MouseLeftUp = 0x0004; 
    public static int MouseRightDown = 0x0008, MouseRightUp = 0x0010; // best guess on the 0010 
    public static int MiddleMouseDown = 0x20, MiddleMouseUp = 0x40; 
    public static int MouseWheel = 0x800; 
} 

答えて

1

ズームアウト

Windows Input Simulatorため
Win + -に拡大鏡
ズーム用 Win + +を開始するためのウィンドウにショートカットキー

Win + =を送ることができますが

キーWindowsロゴのようにキーを送信するための良いライブラリです
+0

。誰がそれをどうやって行うのですか? WinボタンのSendWaitキーが表示されません。 – tsilb

+0

SendWait/SendKeysの代わりにスキャンコードを送信しなければならなかったのは、明らかにスキャンコードがありますが、キーストロークがないためです。奇妙なことに、それはただ1つのメタであり、ctrl/alt/shiftではありません。それらはキーストロークコードを持っています。 – tsilb

+0

SendKeysでwinkeyを送信できない理由を理解できませんか? –

関連する問題