Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/OpenKey/engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
#define HAS_OPTION(data) ((data & 0x200) ? 1 : 0)
#define HAS_COMMAND(data) ((data & 0x400) ? 1 : 0)
#define HAS_SHIFT(data) ((data & 0x800) ? 1 : 0)
#define HAS_FN(data) ((data & 0x1000) ? 1 : 0)
#define GET_BOOL(data) (data ? 1 : 0)
#define HAS_BEEP(data) (data & 0x8000)
#define SET_SWITCH_KEY(data, key) data = (data & 0xFF) | key
#define SET_CONTROL_KEY(data, val) data|=val<<8;
#define SET_OPTION_KEY(data, val) data|=val<<9;
#define SET_COMMAND_KEY(data, val) data|=val<<10;
#define SET_FN_KEY(data, val) data|=val<<12;

//define these variable in your application
//API
Expand Down
40 changes: 28 additions & 12 deletions Sources/OpenKey/macOS/ModernKey/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,35 @@ -(void)askPermission {

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
appDelegate = self;

[self registerSupportedNotification];

//set quick tooltip
[[NSUserDefaults standardUserDefaults] setObject: [NSNumber numberWithInt: 50]
forKey: @"NSInitialToolTipDelay"];

//check whether this app has been launched before that or not
NSArray* runningApp = [[NSWorkspace sharedWorkspace] runningApplications];
if ([runningApp containsObject:OPENKEY_BUNDLE]) { //if already running -> exit
[NSApp terminate:nil];
return;
}

// check if user granted Accessabilty permission
if (!MJAccessibilityIsEnabled()) {
[self askPermission];
return;
}

vShowIconOnDock = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"vShowIconOnDock"];
if (vShowIconOnDock)
[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];

if (vSwitchKeyStatus & 0x8000)
NSBeep();

[self createStatusBarMenu];

//init
dispatch_async(dispatch_get_main_queue(), ^{
if (![OpenKeyManager initEventTap]) {
Expand Down Expand Up @@ -475,22 +475,36 @@ -(void) onControlPanelSelected {
if (_mainWC == nil) {
_mainWC = [[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"OpenKey"];
}
//[OpenKeyManager showDockIcon:YES];
if ([_mainWC.window isVisible]) {
[NSApp activateIgnoringOtherApps:YES];
return;
}
[NSApp activateIgnoringOtherApps:YES];
[_mainWC.window makeKeyAndOrderFront:nil];
[_mainWC.window setLevel:NSFloatingWindowLevel];

// Center on the primary screen — saved frames from prior multi-display
// setups can land the window off-screen.
[_mainWC.window setFrameAutosaveName:@""];
NSScreen *primary = [NSScreen screens].firstObject ?: [NSScreen mainScreen];
NSRect visible = primary.visibleFrame;
NSRect frame = _mainWC.window.frame;
NSPoint origin = NSMakePoint(
visible.origin.x + (visible.size.width - frame.size.width) / 2,
visible.origin.y + (visible.size.height - frame.size.height) / 2);
[_mainWC.window setFrameOrigin:origin];
}

-(void) onMacroSelected {
if (_macroWC == nil) {
_macroWC = [[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"MacroWindow"];
}
//[OpenKeyManager showDockIcon:YES];
if ([_macroWC.window isVisible])
if ([_macroWC.window isVisible]) {
[NSApp activateIgnoringOtherApps:YES];
return;

}
[NSApp activateIgnoringOtherApps:YES];
[_macroWC.window makeKeyAndOrderFront:nil];
[_macroWC.window setLevel:NSFloatingWindowLevel];
}
Expand All @@ -500,9 +514,11 @@ -(void) onAboutSelected {
_aboutWC = [[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"AboutWindow"];
}
//[OpenKeyManager showDockIcon:YES];
if ([_aboutWC.window isVisible])
if ([_aboutWC.window isVisible]) {
[NSApp activateIgnoringOtherApps:YES];
return;

}
[NSApp activateIgnoringOtherApps:YES];
[_aboutWC.window makeKeyAndOrderFront:nil];
[_aboutWC.window setLevel:NSFloatingWindowLevel];
}
Expand Down
47 changes: 34 additions & 13 deletions Sources/OpenKey/macOS/ModernKey/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -889,18 +889,18 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<box fixedFrame="YES" boxType="custom" cornerRadius="4" title="Điều khiển" translatesAutoresizingMaskIntoConstraints="NO" id="t0y-Jm-kod">
<rect key="frame" x="20" y="1036" width="520" height="112"/>
<rect key="frame" x="20" y="1036" width="520" height="137"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" id="wfJ-3h-cfc">
<rect key="frame" x="1" y="1" width="518" height="110"/>
<rect key="frame" x="1" y="1" width="518" height="135"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view>
<color key="borderColor" name="separatorColor" catalog="System" colorSpace="catalog"/>
<color key="fillColor" name="alternatingContentBackgroundColor" catalog="System" colorSpace="catalog"/>
<font key="titleFont" metaFont="system"/>
</box>
<button toolTip="Phím Shift" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wh2-uV-nSn">
<rect key="frame" x="295" y="1082" width="34" height="18"/>
<rect key="frame" x="295" y="1107" width="34" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="⇧" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Wfz-i8-TNp">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -910,8 +910,28 @@
<action selector="onShiftSwitchKey:" target="XfG-lQ-9wD" id="cjW-vM-nFX"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Fn1-K3-Y04">
<rect key="frame" x="130" y="1083" width="390" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" title="Để dùng phím 🌐, vào Cài đặt Hệ thống → Bàn phím → Khi nhấn 🌐: Không làm gì cả" id="Fn1-K3-Y05">
<font key="font" size="10" name="HelveticaNeue-Italic"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button toolTip="Phím Fn (🌐 Globe) trên bàn phím Mac đời mới. Yêu cầu Cài đặt Hệ thống → Bàn phím → Khi nhấn 🌐: Không làm gì cả." verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Fn1-K3-Y01">
<rect key="frame" x="333" y="1107" width="40" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="🌐" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Fn1-K3-Y02">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="onFnSwitchKey:" target="XfG-lQ-9wD" id="Fn1-K3-Y03"/>
</connections>
</button>
<button toolTip="Kêu tiếng beep mỗi khi chuyển chế độ, không có tác dụng với tính năng chuyển chế độ thông minh" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="bJy-t3-bzy">
<rect key="frame" x="423" y="1082" width="79" height="18"/>
<rect key="frame" x="455" y="1107" width="79" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Kêu beep" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Lh1-wK-W31">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -922,7 +942,7 @@
</connections>
</button>
<button toolTip="Phím Control" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5e5-3S-Gd8">
<rect key="frame" x="130" y="1082" width="34" height="18"/>
<rect key="frame" x="130" y="1107" width="34" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="⌃" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="RSz-p1-5PA">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -933,7 +953,7 @@
</connections>
</button>
<button toolTip="Phím Option" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Mox-UL-j9u">
<rect key="frame" x="185" y="1082" width="34" height="18"/>
<rect key="frame" x="185" y="1107" width="34" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="⌥" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="9YC-ED-crZ">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -944,7 +964,7 @@
</connections>
</button>
<button toolTip="Phím Command" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qvz-oU-TII">
<rect key="frame" x="240" y="1082" width="34" height="18"/>
<rect key="frame" x="240" y="1107" width="34" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="⌘" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="1e6-xZ-tnC">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -955,7 +975,7 @@
</connections>
</button>
<textField toolTip="Nhập ký tự vào đây" verticalHuggingPriority="750" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="F2s-m3-A6w" customClass="MyTextField">
<rect key="frame" x="350" y="1078" width="60" height="25"/>
<rect key="frame" x="382" y="1103" width="60" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" alignment="center" title="z" drawsBackground="YES" usesSingleLineMode="YES" id="KXO-pT-dst">
<font key="font" metaFont="system"/>
Expand All @@ -967,7 +987,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VTh-fX-IlB">
<rect key="frame" x="38" y="1118" width="54" height="17"/>
<rect key="frame" x="38" y="1143" width="54" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" title="Kiểu gõ:" id="Ph3-HI-YUI">
<font key="font" usesAppearanceFont="YES"/>
Expand All @@ -976,7 +996,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vki-tN-cYc">
<rect key="frame" x="295" y="1117" width="61" height="17"/>
<rect key="frame" x="295" y="1142" width="61" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Bảng mã:" id="kAU-32-upN">
<font key="font" usesAppearanceFont="YES"/>
Expand All @@ -985,7 +1005,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="efp-Yx-VYL">
<rect key="frame" x="38" y="1083" width="86" height="17"/>
<rect key="frame" x="38" y="1108" width="86" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Phím chuyển:" id="dSf-bA-q9f">
<font key="font" usesAppearanceFont="YES"/>
Expand All @@ -994,7 +1014,7 @@
</textFieldCell>
</textField>
<popUpButton toolTip="Lựa chọn kiểu gõ của bạn" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="pSJ-2j-2yI">
<rect key="frame" x="130" y="1112" width="129" height="25"/>
<rect key="frame" x="130" y="1137" width="129" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Telex" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="y7i-dK-uIA" id="fLB-yN-zN7">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -1012,7 +1032,7 @@
</connections>
</popUpButton>
<popUpButton toolTip="Chọn bảng mã cần gõ, thường là Unicode" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9pW-S5-fU9">
<rect key="frame" x="375" y="1112" width="128" height="25"/>
<rect key="frame" x="375" y="1137" width="128" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Unicode" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="SPQ-uQ-a3m" id="XHz-cv-L4E">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -1692,6 +1712,7 @@
<outlet property="CustomSwitchKey" destination="F2s-m3-A6w" id="xrK-un-OiP"/>
<outlet property="CustomSwitchOption" destination="Mox-UL-j9u" id="iCB-jD-eQG"/>
<outlet property="CustomSwitchShift" destination="wh2-uV-nSn" id="uJw-Tj-F5N"/>
<outlet property="CustomSwitchFn" destination="Fn1-K3-Y01" id="Fn1-K3-Y06"/>
<outlet property="EngButton" destination="yUA-UQ-mxx" id="QKJ-tU-dsA"/>
<outlet property="FixChromiumBrowser" destination="efe-07-OlS" id="PMH-MH-7Ea"/>
<outlet property="FixRecommendBrowser" destination="BKq-hz-RRL" id="V6H-kl-20B"/>
Expand Down
2 changes: 2 additions & 0 deletions Sources/OpenKey/macOS/ModernKey/OpenKey.mm
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ bool checkHotKey(int hotKeyData, bool checkKeyCode=true) {
return false;
if (HAS_SHIFT(hotKeyData) ^ GET_BOOL(_lastFlag & kCGEventFlagMaskShift))
return false;
if (HAS_FN(hotKeyData) ^ GET_BOOL(_lastFlag & kCGEventFlagMaskSecondaryFn))
return false;
if (checkKeyCode) {
if (GET_SWITCH_KEY(hotKeyData) != _keycode)
return false;
Expand Down
9 changes: 4 additions & 5 deletions Sources/OpenKey/macOS/ModernKey/OpenKeyManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ +(BOOL)initEventTap {
// Add to the current run loop.
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);

// Enable the event tap.
// Enable the event tap. The source is on the main run loop, which
// NSApplication is already running — calling CFRunLoopRun() here would
// start a nested loop that blocks AppKit from processing UI events.
CGEventTapEnable(eventTap, true);

// Set it all running.
CFRunLoopRun();


return YES;
}

Expand Down
Loading