Skip to content

Send key events to any running application.

License

Notifications You must be signed in to change notification settings

johnbean393/KeySender

 
 

Repository files navigation

KeySender

Continuous Integration Swift Versions Release License

A simple micro package that enables you to send key events to any running application.

Install

Add the following dependency to your Package.swift file:

.package(url: "https://github.com/jordanbaird/KeySender", from: "0.0.5")

Usage

Create a key sender using one of several initializers. You can create an instance with multiple key events that will be sent in succession, a single key event, a key and some modifiers, or a string. You then call one of the send(to:) or trySend(to:) methods to send the event to a running application of your choice, or sendGlobally() to send the event to the system.

When sending to an application, as long as it can accept the keys that you send and is currently running, the effect will be the same as if the keys had been entered manually.

When sending globally, the effect will also be the same as if the keys had been entered manually.

let sender = KeySender(key: .c, modifiers: .command)
try sender.send(to: "TextEdit")

let sender = KeySender(string: "Hello")
sender.trySend(to: "TextEdit")

let sender = KeySender(key: .space, modifiers: .command)
sender.sendGlobally()

This fork of KeySender provides a KeyRecorder view, which you can use to record keys pressed.

struct MyView: View {

	@State private var keys: [KeyEvent.Key] = []
	@State private var modifier: [KeyEvent.Modifier] = []
	
	var body: some View {
		HStack {
			Text("Record a shortcut:")
			KeyRecorder(
				keys: $keys
				modifer: $keys
			)
		}
	}
	
}

}

Source Stability

As KeySender is under active development, source stability is not guaranteed between releases.

License

KeySender is available under the MIT license.

About

Send key events to any running application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%