话不多说上代码,如需详细查看请下载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开发前3天的产物,比较粗糙,请大家见谅,如需使用请注意阅读使用说明书。
支持功能:
1.txt文件导入
2.背景,文字大小,颜色,显示字数设置
3.自动阅读,可改变换行时间间隔
4.查找
Demo下载链接:ZZReaderDemo
ZZReader :ZZReaderDMG
Demo演示:
Demo里面包含知识点:
1.自定义状态栏
2.键盘及鼠标事件监听
3.文件读取(NSOpenPanel + NSFileHandle)
4.各种控件的使用 NSView,NSButton,NSTextField,NSImageView,NSComboBox,NSMenu,NSPopover等
5.坐标系覆盖
打包软件用的:DMG Canvas
ICON软件:ICON Maker