Emulating Cmd+~ 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];
精彩评论