开发者

Emulating Cmd+~ in Cocoa

开发者 https://www.devze.com 2023-01-26 09:50 出处:网络
Is there a way to somehow emulate Cmd + ~ shortcut behaviour (i.e. cycling through an application windows) in Cocoa?

Is there a way to somehow emulate Cmd + ~ shortcut behaviour (i.e. cycling through an application windows) in Cocoa?

I was able to do this in Carbon by doing the following:

HICommand cmd;
cmd.attirbutes = kHICommandFromMenu;
cmd开发者_JS百科.commandID = kHICommandRotateWindowsForward;
::GetIndMenuItemWithCommandID( NULL, cmd.commandID, 1, &(cmd.menu.menuRef), &(cmd.menu.menuItemIndex));
::ProcessHICommand(&cmd);

But now I need to do this in Cocoa and can't find a way :) Googled something about a "private method _cycleWindows in NSApplication", which seems to do exactly what I need, but the code

[[NSApplication sharedApplication] _cycleWindows];

won't compile - "wrong method signature".


Using _cycleWindows is the correct thing to do. Try this:

[NSApp sendAction:@selector(_cycleWindows:) to:nil from:nil];

Also, if you want to emulate Cmd+Shift+~ then do:

[NSApp sendAction:@selector(_cycleWindowsBackwards:) to:nil from:nil];

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号