@@ -13,49 +13,63 @@ kotlin {
1313 // Format: groupId:artifactId:version
1414 // groupId = io.github.loop312
1515 // artifactId = compose-keyhandler
16- // version = 0.2.1 (choose latest version instead)
17- implementation(" io.github.loop312:compose-keyhandler:0.2.1 " )
16+ // version = 0.5.0 (choose latest version instead)
17+ implementation(" io.github.loop312:compose-keyhandler:0.5.0 " )
1818 }
1919 }
2020}
2121```
2222
2323``` kotlin
24- implementation(" io.github.loop312:compose-keyhandler:0.2.1 " )
24+ implementation(" io.github.loop312:compose-keyhandler:0.5.0 " )
2525```
2626
2727### Common Main
2828``` kotlin
29+ // import io.github.loop312.compose_keyhandler.KeyHandler
2930// 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- }
4331
4432fun main () {
33+ // KeyHandler(false) will not consume key events
34+ val keyHandler = KeyHandler ()
35+
36+ // continuous execution
37+ keyHandler.addKey(Key .A ) {
38+ println (" A is being pressed" )
39+ // or any other action you want to do
40+ }
41+
42+ // one-time execution
43+ keyHandler.addSingleActionKey(Key .B ) {
44+ println (" B was pressed" )
45+ // or any other action you want to do
46+ }
47+
48+ // on release execution
49+ keyHandler.addReleaseKey(Key .C ) {
50+ println (" C was released" )
51+ // or any other action you want to do
52+ }
53+
54+ // continuous combination execution
55+ keyHandler.addCombination(setOf (Key .D , Key .E )) {
56+ println (" DE is being pressed" )
57+ // or any other action you want to do
58+ }
59+
60+ // one-time combination execution
61+ keyHandler.addSingleActionCombination(setOf (Key .F , Key .G )) {
62+ println (" FG was pressed" )
63+ // or any other action you want to do
64+ }
65+ // or Modifier.onPreviewKeyEvent(keyHandler.listen)
4566 Box (Modifier .onKeyEvent(keyHandler.listen)) {
4667 // ...
4768 }
48- keyHandler.activate()
4969}
5070```
5171
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-
72+ ### NOTE: Make sure object with modifier ` onKeyEvent ` or ` onPreviewKeyEvent ` is in focus
5973
6074# Came With Project Structure
6175
0 commit comments