GithubHelp home page GithubHelp logo

jordanbaird / keysender Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 1.0 58 KB

Send key events to any running application.

License: MIT License

Swift 100.00%
swift key-event event-sender key-commands keypress keypressevent keystrokes key-sender cgevent

keysender's Introduction

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()

Source Stability

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

License

KeySender is available under the MIT license.

keysender's People

Contributors

jordanbaird avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

little-big-h

keysender's Issues

Does not work for me

Hey @jordanbaird, your package is exactly what I was looking for. Thanks a lot. But unfortunately it doesn't work for me. I created a minimal console application to give it a try. I expect this line to open TextEdit and put the string "Hello".

try KeySender(for: "Hello World").openApplicationAndSend("TextEdit")

But unfortunately only TextEdit opens but not text appears. I already grant accessibility permissions for my console application. Do you have any idea what else could be missing?

EDIT 1: I found out that the behaviour described is related to that: https://stackoverflow.com/q/63094246. The conclusion is that adding a sleep after the line above helps. Does anyone knows a better solution?

Cheers
mahush

Not seeing results

Attempted to utilize today and did not see any results.

Here is my current code.

let sender = KeySender(key: .rightArrow)
		sender.trySend(to: "TextEdit")

Some things to note:

  1. I first attempted to send .rightArrow to an app to advance to the next slide where this key will do that, but nothing happened. I did get errors a bit as I had to poke around for the actual app name, but once I got the app name, still nothing.
  2. Then I tried a similar task in Slack, moving the cursor, but nothing happened. I also tried to type a letter but nothing happened.
  3. Finally I switched to TextEdit since that was in the example and tried sending .rightArrow and .c but those didn't work either.

My thought is that I have a permissions problem?

I'm building this as a SwiftUI Mac App in XCode 14.3.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.