話不多說(shuō)上代碼,如需詳細(xì)查看請(qǐng)下載ZZReaderDemo?
#pragma mark —— 快捷鍵
- (void)initializeStatus
{?
? ? [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hotKeyNoti:) name:NOTI_HOTKEY object:nil];
? ? [self setHotKey];?
}
- (void)hotKeyNoti:(NSNotification *)noti
{
? ? NSInteger hotKeyID = [[noti.userInfo objectForKey:@"hotKeyID"] intValue];
? ? ?switch (hotKeyID)
? ? {
? ? ? ? case kVK_LeftArrow://上一行
? ? ? ? {
? ? ? ? }
? ? ? ? ? ? break;
? ? ? ? case kVK_RightArrow://下一行
? ? ? ? {
? ? ? ? ? ? ?}
? ? ? ? }
? ? ? ? ? ? break;?
? ? ? ? default:
? ? ? ? ? ? break;
? ? }
}
OSStatus GlobalHotKeyHandler(EventHandlerCallRef nextHandler,EventRef theEvent,
? ? ? ? ? ? ? ? ? ? ? ? ? ? void *userData)
{
? ? EventHotKeyID hkCom;
? ? GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,
? ? ? ? ? ? ? ? ? ? ? sizeof(hkCom),NULL,&hkCom);
? ? unsigned int hotKeyId = hkCom.id;
? ? [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_HOTKEY object:nil userInfo:@{@"hotKeyID": @(hotKeyId)}];
? ? return noErr;
}
- (void)setHotKey
{
? ? [self registHotKey];?
}
/**
* 添加全局的快捷鍵
**/
-(void)registHotKey
{
? ? [self hotKeyUpdate:kVK_LeftArrow];?
? ? [self hotKeyUpdate:kVK_RightArrow]; ?
}
-(void)hotKeyUpdate:(NSInteger)keyCode
{
? ? EventHotKeyRef? ? ? gMyHotKeyRef;
? ? EventHotKeyID? ? ? ? gMyHotKeyID;
? ? EventTypeSpec? ? ? ? eventType;
? ? eventType.eventClass = kEventClassKeyboard;
? ? eventType.eventKind = kEventHotKeyPressed;
? ? InstallApplicationEventHandler(&GlobalHotKeyHandler,1,&eventType,NULL,NULL);
? ? gMyHotKeyID.signature = 'zick';
? ? gMyHotKeyID.id = keyCode;
? ? if (keyCode == kVK_ANSI_F)
? ? {
? ? ? ? RegisterEventHotKey(keyCode, cmdKey+optionKey, gMyHotKeyID,GetApplicationEventTarget(), 0, &gMyHotKeyRef);
? ? }
? ? else if (keyCode == kVK_Space)
? ? {
? ? ? ? RegisterEventHotKey(keyCode, cmdKey, gMyHotKeyID,GetApplicationEventTarget(), 0, &gMyHotKeyRef);
? ? }
? ? else
? ? {?
? ? ? ? RegisterEventHotKey(keyCode, 0, gMyHotKeyID,GetApplicationEventTarget(), 0, &gMyHotKeyRef);
? ? }?
}?
? ? ?一款躲在Mac菜單欄上的txt閱讀器,此APP是我學(xué)習(xí)mac app開(kāi)發(fā)前3天的產(chǎn)物,比較粗糙,請(qǐng)大家見(jiàn)諒,如需使用請(qǐng)注意閱讀使用說(shuō)明書(shū)。
支持功能:
1.txt文件導(dǎo)入
2.背景,文字大小,顏色,顯示字?jǐn)?shù)設(shè)置
3.自動(dòng)閱讀,可改變換行時(shí)間間隔
4.查找
Demo下載鏈接:ZZReaderDemo
ZZReader :ZZReaderDMG
Demo演示:
Demo里面包含知識(shí)點(diǎn):
1.自定義狀態(tài)欄
2.鍵盤(pán)及鼠標(biāo)事件監(jiān)聽(tīng)?
3.文件讀取(NSOpenPanel +?NSFileHandle)
4.各種控件的使用 NSView,NSButton,NSTextField,NSImageView,NSComboBox,NSMenu,NSPopover等
5.坐標(biāo)系覆蓋 ?
打包軟件用的:DMG Canvas
ICON軟件:ICON Maker