Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Listen and SimulateKeyPress #1

Merged
merged 4 commits into from
Jun 2, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
docs: autoupdate
  • Loading branch information
MarvinJWendt committed Jun 2, 2022
commit 905a263573b473fb7e1c5ab09f9a109efd62d980
110 changes: 25 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,12 @@
<img src="https://raw.githubusercontent.com/atomicgo/atomicgo/main/assets/header.png" alt="AtomicGo">
</p>

## Description

Package keyboard can be used to read key presses from the keyboard, while in a
terminal application. It's crossplatform and keypresses can be combined to check
for ctrl+c, alt+4, ctrl-shift, alt+ctrl+right, etc.

Works nicely with https://atomicgo.dev/cursor

```go

keyboard.StartListener()
defer keyboard.StopListener()

for {
keyInfo, _ := keyboard.GetKey()
key := keyInfo.Code

if key == keys.CtrlC {
break
}

fmt.Println("\r", keyInfo.String())
}

```

## Install

<p align="center">
<table>
<tbody>
<td align="center">
<img width="2000" height="0"><br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------------------------------------------------------------------------------------------------------
<img width="2000" height="0">
</td>
</tbody>
Expand All @@ -91,91 +63,59 @@ Works nicely with https://atomicgo.dev/cursor
<tbody>
<td align="center">
<img width="2000" height="0"><br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------------------------------------------------------------------------------------------------------
<img width="2000" height="0">
</td>
</tbody>
</table>
</p>

```go
// Add this to your imports
import "atomicgo.dev/keyboard"
```
## Description

## Usage
Package keyboard can be used to read key presses from the keyboard, while in a
terminal application. It's crossplatform and keypresses can be combined to check
for ctrl+c, alt+4, ctrl-shift, alt+ctrl+right, etc.

#### func GetKey
Works nicely with https://atomicgo.dev/cursor

```go
func GetKey() (keys.Key, error)
```
GetKey blocks until a key is pressed and returns the key info.

Example:

keyboard.StartListener()
defer keyboard.StopListener()

for {
keyInfo, _ := keyboard.GetKey()
key := keyInfo.Code
keyInfo, _ := keyboard.GetKey()
key := keyInfo.Code

if key == keys.CtrlC {
break
}
if key == keys.CtrlC {
break
}

fmt.Println("\r", keyInfo.String())
fmt.Println("\r", keyInfo.String())
}

keyboard.StopListener()

#### func StartListener

```go
func StartListener() error
```
StartListener starts the keyboard listener

Example:

keyboard.StartListener()

for {
keyInfo, _ := keyboard.GetKey()
key := keyInfo.Code

if key == keys.CtrlC {
break
}

fmt.Println("\r", keyInfo.String())
}

keyboard.StopListener()
## Usage

#### func StopListener
#### func GetListener

```go
func StopListener() error
func GetListener() (listener chan keys.Key, cancel chan bool)
```
StopListener stops the keyboard listener

Example:

keyboard.StartListener()

for {
keyInfo, _ := keyboard.GetKey()
key := keyInfo.Code
#### func Listen

if key == keys.CtrlC {
break
}
```go
func Listen(onKeyPress func(keyInfo keys.Key) (stop bool, err error)) error
```

fmt.Println("\r", keyInfo.String())
}
#### func MockKey

keyboard.StopListener()
```go
func MockKey(key keys.Key) error
```

---

Expand Down