話不多說上代碼株婴,如需詳細查看請下載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是我學習mac app開發(fā)前3天的產物复濒,比較粗糙,請大家見諒,如需使用請注意閱讀使用說明書冻璃。
支持功能:
1.txt文件導入
2.背景档插,文字大小捌归,顏色,顯示字數(shù)設置
3.自動閱讀告喊,可改變換行時間間隔
4.查找
Demo下載鏈接:ZZReaderDemo
ZZReader :ZZReaderDMG
Demo演示:
Demo里面包含知識點:
1.自定義狀態(tài)欄
2.鍵盤及鼠標事件監(jiān)聽?
3.文件讀若镏簟(NSOpenPanel +?NSFileHandle)
4.各種控件的使用 NSView,NSButton,NSTextField,NSImageView,NSComboBox,NSMenu,NSPopover等
5.坐標系覆蓋 ?
打包軟件用的:DMG Canvas
ICON軟件:ICON Maker