Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit f977ed2

Browse files
committed
update
1 parent 7f3272f commit f977ed2

36 files changed

+538
-110
lines changed

KeyCast.xcodeproj/project.pbxproj

+21-8
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
28398B1E1A8D924F009BBEBE /* processlist.c in Sources */ = {isa = PBXBuildFile; fileRef = 28398B1D1A8D924F009BBEBE /* processlist.c */; };
1011
28485C551A84AFF000667ECB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28485C541A84AFF000667ECB /* AppDelegate.swift */; };
1112
28485C571A84AFF000667ECB /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 28485C561A84AFF000667ECB /* Images.xcassets */; };
1213
28485C5A1A84AFF000667ECB /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28485C581A84AFF000667ECB /* MainMenu.xib */; };
1314
28485C661A84AFF100667ECB /* KeyCastTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28485C651A84AFF100667ECB /* KeyCastTests.swift */; };
1415
285ED37E1A888C4E00E97321 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 285ED37D1A888C4E00E97321 /* PreferencesWindowController.swift */; };
16+
286F3C4A1A8DF94800D56393 /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 286F3C491A8DF94800D56393 /* Toast.swift */; };
17+
28F478381A8D933800E88A71 /* app.sdef in Resources */ = {isa = PBXBuildFile; fileRef = 28F478371A8D933800E88A71 /* app.sdef */; };
18+
28F4783E1A8DBB9F00E88A71 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28F4783D1A8DBB9F00E88A71 /* Utils.swift */; };
1519
28FD3B861A88596600D6A1C4 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28FD3B851A88596600D6A1C4 /* MainView.swift */; };
1620
74547BE11A8A559D003A079A /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 74547BE01A8A559D003A079A /* README.md */; };
1721
748E2EC91A87AF3100F5B319 /* Accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 748E2EC81A87AF3100F5B319 /* Accessibility.swift */; };
18-
74C19DB71A891BFA00ADED08 /* icon-menu.png in Resources */ = {isa = PBXBuildFile; fileRef = 74C19DB51A891BFA00ADED08 /* icon-menu.png */; };
19-
74C19DB81A891BFA00ADED08 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 74C19DB61A891BFA00ADED08 /* [email protected] */; };
2022
/* End PBXBuildFile section */
2123

2224
/* Begin PBXContainerItemProxy section */
@@ -32,6 +34,7 @@
3234
/* Begin PBXFileReference section */
3335
282BCF531A8A0C1200472C8A /* KeyCast-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KeyCast-Bridging-Header.h"; sourceTree = "<group>"; };
3436
282BCF551A8A0C1300472C8A /* processlist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = processlist.h; sourceTree = "<group>"; };
37+
28398B1D1A8D924F009BBEBE /* processlist.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = processlist.c; sourceTree = "<group>"; };
3538
28485C4F1A84AFF000667ECB /* KeyCast.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KeyCast.app; sourceTree = BUILT_PRODUCTS_DIR; };
3639
28485C531A84AFF000667ECB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3740
28485C541A84AFF000667ECB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -41,11 +44,12 @@
4144
28485C641A84AFF100667ECB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4245
28485C651A84AFF100667ECB /* KeyCastTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyCastTests.swift; sourceTree = "<group>"; };
4346
285ED37D1A888C4E00E97321 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
47+
286F3C491A8DF94800D56393 /* Toast.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Toast.swift; sourceTree = "<group>"; };
48+
28F478371A8D933800E88A71 /* app.sdef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = app.sdef; sourceTree = "<group>"; };
49+
28F4783D1A8DBB9F00E88A71 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
4450
28FD3B851A88596600D6A1C4 /* MainView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
4551
74547BE01A8A559D003A079A /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
4652
748E2EC81A87AF3100F5B319 /* Accessibility.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Accessibility.swift; sourceTree = "<group>"; };
47-
74C19DB51A891BFA00ADED08 /* icon-menu.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-menu.png"; sourceTree = "<group>"; };
48-
74C19DB61A891BFA00ADED08 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
4953
/* End PBXFileReference section */
5054

5155
/* Begin PBXFrameworksBuildPhase section */
@@ -87,10 +91,9 @@
8791
28485C511A84AFF000667ECB /* KeyCast */ = {
8892
isa = PBXGroup;
8993
children = (
90-
74C19DB51A891BFA00ADED08 /* icon-menu.png */,
91-
74C19DB61A891BFA00ADED08 /* [email protected] */,
9294
28485C541A84AFF000667ECB /* AppDelegate.swift */,
9395
74547BE01A8A559D003A079A /* README.md */,
96+
28398B1D1A8D924F009BBEBE /* processlist.c */,
9497
282BCF551A8A0C1300472C8A /* processlist.h */,
9598
28485C561A84AFF000667ECB /* Images.xcassets */,
9699
28485C581A84AFF000667ECB /* MainMenu.xib */,
@@ -99,6 +102,9 @@
99102
28FD3B851A88596600D6A1C4 /* MainView.swift */,
100103
285ED37D1A888C4E00E97321 /* PreferencesWindowController.swift */,
101104
282BCF531A8A0C1200472C8A /* KeyCast-Bridging-Header.h */,
105+
28F478371A8D933800E88A71 /* app.sdef */,
106+
28F4783D1A8DBB9F00E88A71 /* Utils.swift */,
107+
286F3C491A8DF94800D56393 /* Toast.swift */,
102108
);
103109
path = KeyCast;
104110
sourceTree = "<group>";
@@ -177,6 +183,11 @@
177183
TargetAttributes = {
178184
28485C4E1A84AFF000667ECB = {
179185
CreatedOnToolsVersion = 6.1.1;
186+
SystemCapabilities = {
187+
com.apple.Sandbox = {
188+
enabled = 0;
189+
};
190+
};
180191
};
181192
28485C5E1A84AFF100667ECB = {
182193
CreatedOnToolsVersion = 6.1.1;
@@ -208,8 +219,7 @@
208219
isa = PBXResourcesBuildPhase;
209220
buildActionMask = 2147483647;
210221
files = (
211-
74C19DB81A891BFA00ADED08 /* [email protected] in Resources */,
212-
74C19DB71A891BFA00ADED08 /* icon-menu.png in Resources */,
222+
28F478381A8D933800E88A71 /* app.sdef in Resources */,
213223
28485C571A84AFF000667ECB /* Images.xcassets in Resources */,
214224
28485C5A1A84AFF000667ECB /* MainMenu.xib in Resources */,
215225
);
@@ -230,7 +240,10 @@
230240
buildActionMask = 2147483647;
231241
files = (
232242
748E2EC91A87AF3100F5B319 /* Accessibility.swift in Sources */,
243+
286F3C4A1A8DF94800D56393 /* Toast.swift in Sources */,
244+
28398B1E1A8D924F009BBEBE /* processlist.c in Sources */,
233245
28FD3B861A88596600D6A1C4 /* MainView.swift in Sources */,
246+
28F4783E1A8DBB9F00E88A71 /* Utils.swift in Sources */,
234247
74547BE11A8A559D003A079A /* README.md in Sources */,
235248
285ED37E1A888C4E00E97321 /* PreferencesWindowController.swift in Sources */,
236249
28485C551A84AFF000667ECB /* AppDelegate.swift in Sources */,

KeyCast/AppDelegate.swift

+43-67
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,25 @@
77

88
import Cocoa
99

10+
1011
@NSApplicationMain
1112
class AppDelegate: NSObject, NSApplicationDelegate {
12-
let REPLACE_MAP: Dictionary<String, String> = [
13-
"\r" : "\n",
14-
"\u{1B}" : "",
15-
"\t" : "",
16-
"\u{19}" : "",
17-
" " : "",
18-
"\u{7f}" : "",
19-
"\u{03}" : "",
20-
"\u{10}" : "",
21-
"\u{F728}" : "",
22-
"\u{F739}" : "",
23-
"\u{F704}" : "[F1]",
24-
"\u{F705}" : "[F2]",
25-
"\u{F706}" : "[F3]",
26-
"\u{F707}" : "[F4]",
27-
"\u{F708}" : "[F5]",
28-
"\u{F709}" : "[F6]",
29-
"\u{F70A}" : "[F7]",
30-
"\u{F70B}" : "[F8]",
31-
"\u{F70C}" : "[F9]",
32-
"\u{F70D}" : "[F10]",
33-
"\u{F70E}" : "[F11]",
34-
"\u{F70F}" : "[F12]",
35-
36-
"\u{F700}" : "",
37-
"\u{F701}" : "",
38-
"\u{F702}" : "",
39-
"\u{F703}" : "",
40-
"\u{F72C}" : "",
41-
"\u{F72D}" : "",
42-
"\u{F729}" : "",
43-
"\u{F72B}" : "",
44-
]
45-
4613
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-1)
47-
var enabled: Bool = true
14+
var enabled: Bool = true {
15+
didSet {
16+
menuEnabled.state = enabled ? 1 : 0
17+
updateMenuTitle()
18+
toast.toast(enabled ? "KeyCast is enabled" : "KeyCast is disabled")
19+
}
20+
}
4821
var window: NSWindow! = nil
4922
var view: MainView! = nil
5023
var prevKeyed: NSDate = NSDate()
5124

5225
@IBOutlet weak var menu: NSMenu!
26+
@IBOutlet weak var menuEnabled: NSMenuItem!
5327
@IBOutlet weak var preferences: PreferencesWindow!
28+
@IBOutlet weak var toast: ToastWindow!
5429

5530
func applicationDidFinishLaunching(aNotification: NSNotification) {
5631

@@ -65,27 +40,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6540
}
6641
// println(e)
6742

68-
var mod = ""
69-
if e.modifierFlags.rawValue & NSEventModifierFlags.ControlKeyMask.rawValue != 0 {
70-
mod += ""
71-
}
72-
if e.modifierFlags.rawValue & NSEventModifierFlags.AlternateKeyMask.rawValue != 0 {
73-
mod += ""
74-
}
75-
if e.modifierFlags.rawValue & NSEventModifierFlags.ShiftKeyMask.rawValue != 0 {
76-
mod += ""
77-
}
78-
if e.modifierFlags.rawValue & NSEventModifierFlags.CommandKeyMask.rawValue != 0 {
79-
mod += ""
80-
}
8143

8244

8345
for c in e.charactersIgnoringModifiers!.uppercaseString.unicodeScalars {
8446
println(NSString(format: "%08X", c.value));
8547
}
8648

49+
let (mod, char) = Utils.keyStringFromEvent(e)
8750

88-
let char = self.keyToReadableString(e.charactersIgnoringModifiers!.uppercaseString)
8951
if mod.isEmpty {
9052
let interval = NSDate().timeIntervalSinceDate(self.prevKeyed)
9153
if interval > 1 {
@@ -101,8 +63,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
10163
self.prevKeyed = NSDate()
10264
}
10365

104-
preferences.initControls()
105-
10666
let rect = NSRect(x: 0, y: 0, width: 800, height: 500)
10767
window = NSWindow(contentRect: rect, styleMask: NSBorderlessWindowMask, backing: NSBackingStoreType.Buffered, defer: false)
10868
window.opaque = false
@@ -130,7 +90,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
13090
name: NSUserDefaultsDidChangeNotification,
13191
object: nil
13292
)
133-
self.userDefaultsDidChange(NSNotification())
93+
userDefaultsDidChange(nil)
13494

13595

13696
/*
@@ -143,11 +103,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
143103
*/
144104

145105
enableGlobalAccessibilityFeatures()
106+
toast.toast("Initialized")
146107
}
147108

148109
// VoiceOver が起動していない限りアクセシビリティオブジェクトを作らない一部アプリケーション用 (eg. Google Chrome) に
149110
// VoiceOver がセットする属性をセットする。VoiceOver 判定のため自プロセスには設定しない
150111
func enableGlobalAccessibilityFeatures() {
112+
println("enableGlobalAccessibilityFeatures")
151113
NSWorkspace.sharedWorkspace().notificationCenter.addObserver(
152114
self,
153115
selector: "enableAccessibilityForNewApplication:",
@@ -162,7 +124,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
162124
continue
163125
}
164126
let app = AXUIElementCreateApplication(application.processIdentifier).takeRetainedValue()
165-
127+
println("enableGlobalAccessibilityFeatures: \(app)")
166128
AXUIElementCopyAttributeValue(app, "AXEnhancedUserInterface", &ptr)
167129
AXUIElementSetAttributeValue(app, "AXEnhancedUserInterface", 1)
168130
}
@@ -216,7 +178,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
216178
return false
217179
}
218180

219-
func userDefaultsDidChange(aNotification: NSNotification) {
181+
func userDefaultsDidChange(aNotification: NSNotification!) {
220182
window.alphaValue = CGFloat(preferences.opacity) / 100.0
221183
self.resize(preferences.width, height: preferences.height)
222184
view.shadowCount = preferences.shadow
@@ -235,24 +197,28 @@ class AppDelegate: NSObject, NSApplicationDelegate {
235197
view.setFrameSize(NSSize(width: rect.width, height: rect.height))
236198
}
237199

238-
func keyToReadableString (string: String)-> String {
239-
var str = string
240-
for (k, v) in self.REPLACE_MAP {
241-
str = str.stringByReplacingOccurrencesOfString(k, withString: v)
242-
}
243-
return str
244-
}
245-
246-
247200
func updateMenuTitle() {
248201
statusItem.title = (enabled ? "\u{2713} " : " ") + NSRunningApplication.currentApplication().localizedName!
249202
}
250203

251204
func canShowInput()-> Bool {
252-
return enabled && canShowInputByFocusedUIElement()
205+
return enabled && canShowInputByRunningProcesses() && canShowInputByFocusedUIElement()
206+
}
207+
208+
func canShowInputByRunningProcesses()->Bool {
209+
if !preferences.hideSudoInProcessList {
210+
return true
211+
}
212+
213+
// sudo 実行中は入力を表示しない
214+
return !IsInBSDProcessList("sudo")
253215
}
254216

255217
func canShowInputByFocusedUIElement()->Bool {
218+
if !preferences.hideNativePasswordInput {
219+
return true
220+
}
221+
256222
var ptr: Unmanaged<AnyObject>?
257223

258224
let system = AXUIElementCreateSystemWide().takeRetainedValue()
@@ -298,6 +264,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
298264
}
299265
*/
300266

267+
/*
301268
if bundleId == "com.apple.Terminal" {
302269
AXUIElementCopyAttributeValue(ui, "AXValue", &ptr)
303270
if ptr != nil {
@@ -312,6 +279,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
312279
}
313280
}
314281
}
282+
*/
315283

316284
AXUIElementCopyAttributeValue(ui, "AXSubrole", &ptr)
317285
if ptr != nil {
@@ -328,15 +296,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
328296

329297
@IBAction func toggleState(sender: NSMenuItem) {
330298
enabled = !enabled
331-
sender.state = enabled ? 1 : 0
332-
updateMenuTitle()
333299
}
300+
334301
@IBAction func clearLog(sender: AnyObject) {
335302
view.clear()
336303
}
337304

338305
@IBAction func openPreferencesWindow(sender: AnyObject) {
339-
preferences.orderFrontRegardless()
306+
preferences.makeKeyAndOrderFront(nil)
340307
}
341308

342309
@IBAction func chooseFont(sender: AnyObject) {
@@ -389,5 +356,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
389356
println(result)
390357
rkkkgg}
391358
*/
359+
360+
// osascript -e 'tell application "KeyCast"' -e 'set enabled to true' -e 'end tell'
361+
// osascript -e 'tell application "KeyCast"' -e 'set enabled to false' -e 'end tell'
362+
override func application(sender: NSApplication, delegateHandlesKey key: String) -> Bool {
363+
if key == "enabled" {
364+
return true
365+
}
366+
return false
367+
}
392368
}
393369

0 commit comments

Comments
 (0)