@@ -32,6 +32,7 @@ import androidx.core.view.updateLayoutParams
32
32
import androidx.lifecycle.lifecycleScope
33
33
import com.osfans.trime.BuildConfig
34
34
import com.osfans.trime.R
35
+ import com.osfans.trime.core.KeyModifier
35
36
import com.osfans.trime.core.KeyModifiers
36
37
import com.osfans.trime.core.KeyValue
37
38
import com.osfans.trime.core.Rime
@@ -768,17 +769,49 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
768
769
769
770
private fun forwardKeyEvent (event : KeyEvent ): Boolean {
770
771
val modifiers = KeyModifiers .fromKeyEvent(event)
772
+ val charCode = event.unicodeChar
773
+ if (charCode > 0 && charCode != ' \t ' .code) {
774
+ postRimeJob {
775
+ if (! processKey(charCode, modifiers.modifiers)) {
776
+ onKeyEventCallback(KeyValue (charCode), modifiers)
777
+ }
778
+ }
779
+ return true
780
+ }
771
781
val keyVal = KeyValue .fromKeyEvent(event)
772
782
if (keyVal.value != RimeKeyMapping .RimeKey_VoidSymbol ) {
773
783
postRimeJob {
774
- processKey(keyVal, modifiers)
784
+ if (! processKey(keyVal, modifiers)) {
785
+ onKeyEventCallback(keyVal, modifiers)
786
+ }
775
787
}
776
788
return true
777
789
}
778
790
Timber .d(" Skipped KeyEvent: $event " )
779
791
return false
780
792
}
781
793
794
+ private fun onKeyEventCallback (
795
+ keyVal : KeyValue ,
796
+ modifiers : KeyModifiers ,
797
+ ) {
798
+ val keyCode = keyVal.keyCode
799
+ if (keyCode != KeyEvent .KEYCODE_UNKNOWN ) {
800
+ val eventTime = SystemClock .uptimeMillis()
801
+ if (modifiers.modifiers == KeyModifier .Release .modifier) {
802
+ sendUpKeyEvent(eventTime, keyCode, modifiers.metaState)
803
+ } else {
804
+ sendDownKeyEvent(eventTime, keyCode, modifiers.metaState)
805
+ }
806
+ } else {
807
+ if (modifiers.modifiers != KeyModifier .Release .modifier && keyVal.value > 0 ) {
808
+ commitText(Char (keyVal.value).toString())
809
+ } else {
810
+ Timber .w(" Unhandled Rime KeyEvent: ($keyVal , $modifiers )" )
811
+ }
812
+ }
813
+ }
814
+
782
815
override fun onKeyDown (
783
816
keyCode : Int ,
784
817
event : KeyEvent ,
0 commit comments