Skip to content

Commit d9abb20

Browse files
authored
Merge pull request #3 from Loop312/test
Test
2 parents e6a9dd8 + f40a68e commit d9abb20

4 files changed

Lines changed: 65 additions & 4 deletions

File tree

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,64 @@
1+
# Usage
2+
3+
*MUST USE WITH COMPOSE MULTIPLATFORM*
4+
### build.gradle.kts
5+
6+
```kotlin
7+
kotlin {
8+
//...
9+
sourceSets {
10+
//...
11+
commonMain.dependencies {
12+
//...
13+
//Format: groupId:artifactId:version
14+
//groupId = io.github.loop312
15+
//artifactId = compose-keyhandler
16+
//version = 0.2.1 (choose latest version instead)
17+
implementation("io.github.loop312:compose-keyhandler:0.2.1")
18+
}
19+
}
20+
}
21+
```
22+
23+
```kotlin
24+
implementation("io.github.loop312:compose-keyhandler:0.2.0")
25+
```
26+
27+
### Common Main
28+
```kotlin
29+
//import ...
30+
/*
31+
import io.github.loop312.compose_keyhandler.KeyHandler
32+
or for more fine control of the variables
33+
import io.github.compose_keyhandler.*
34+
*/
35+
36+
//doesn't need to be outside main function
37+
val keyHandler = KeyHandler()
38+
39+
keyHandler.addKey(Key.A){
40+
println("A is being pressed")
41+
//or any other action you want to do
42+
}
43+
44+
fun main() {
45+
Box(Modifier.onKeyEvent(keyHandler.listen)) {
46+
//...
47+
}
48+
keyHandler.activate()
49+
}
50+
```
51+
52+
## Method
53+
54+
- maps a key to an action
55+
- whenever a key is pressed, it gets added to a set
56+
- whenever a key is released, it gets removed from the set
57+
- while the key is pressed, the action is executed
58+
59+
60+
# Came With Project Structure
61+
162
[![official project](http://jb.gg/badges/official.svg)](https://github.com/JetBrains#jetbrains-on-github)
263

364
# Multiplatform library template

compose-keyhandler/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ plugins {
1515
}
1616

1717
group = "io.github.loop312"
18-
version = "0.2.0"
18+
version = "0.2.1"
1919

2020
kotlin {
2121
androidTarget {

compose-keyhandler/src/commonMain/kotlin/io/github/compose_keyhandler/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fun App() {
2222
MaterialTheme {
2323
var showContent by remember { mutableStateOf(false) }
2424
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
25-
Button(onClick = { showContent = !showContent }, Modifier.onKeyEvent(lol.listener)) {
25+
Button(onClick = { showContent = !showContent }, Modifier.onKeyEvent(lol.listen)) {
2626
Text("Click me!")
2727
}
2828
lol.activate()

compose-keyhandler/src/commonMain/kotlin/io/github/compose_keyhandler/KeyHandler.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class KeyHandler {
1616
keys += mapOf(key to action)
1717
}
1818

19-
//use modifier = "Modifier.onKeyEvent(KeyHandler.listener)"
20-
val listener = { event: KeyEvent ->
19+
//use modifier = "Modifier.onKeyEvent(KeyHandler.listen)"
20+
val listen = { event: KeyEvent ->
2121
//when a button is pressed add it to pressedKeys and when it's released remove it
2222
when (event.type) {
2323
KeyEventType.KeyDown -> {

0 commit comments

Comments
 (0)