<commit_before>Strict

Private

Import bono.src.kernel
Import keyevent
Import keyhandler
Import mojo.input

Public

Class KeyEmitter Implements Updateable, Suspendable
    Private

    Field keyboardEnabled:Bool
    Field event:KeyEvent = New KeyEvent()
    Field lastMode:Bool[255]

    Const UP:Int = 0
    Const DOWN:Int = 1
    Const PRESS:Int = 2

    Public

    Field active:Bool = True
    Field handler:Keyhandler

    Method OnResume:Void()
    End

    Method OnSuspend:Void()
        Reset()
    End

    Method OnUpdate:Void(deltatimer:DeltaTimer)
        If Not handler Then Return

        If Not active
            DisableKeyboard()
        Else
            EnableKeyboard()
            ProcessKeys()
        End
    End

    Private

    Method DisableKeyboard:Void()
        If Not keyboardEnabled Then Return

        keyboardEnabled = False
        input.DisableKeyboard()
        Reset()
    End

    Method Reset:Void()
        For Local i:Int = 0 Until lastMode.Length()
            lastMode[i] = False
        End
    End

    Method EnableKeyboard:Void()
        If keyboardEnabled Then Return

        keyboardEnabled = True
        input.EnableKeyboard()
    End

    Method ProcessKeys:Void()
        Local mode:Bool
        For Local i:Int = 0 Until lastMode.Length()
            mode = (KeyDown(i) = 1)

            If mode = lastMode[i]
                If mode Then DispatchEvent(i, PRESS)<commit_msg>allow active Keyemitter with hidden keyboard<commit_after>Strict

Private

Import bono.src.kernel
Import keyevent
Import keyhandler
Import mojo.input

Public

Class KeyEmitter Implements Updateable, Suspendable
    Private

    Field keyboardEnabled:Bool
    Field event:KeyEvent = New KeyEvent()
    Field lastMode:Bool[255]
    Field dirty:Bool

    Const UP:Int = 0
    Const DOWN:Int = 1
    Const PRESS:Int = 2

    Public

    Field active:Bool = True
    Field handler:Keyhandler
    Field showKeyboard:Bool = True

    Method OnResume:Void()
    End

    Method OnSuspend:Void()
        Reset()
    End

    Method OnUpdate:Void(deltatimer:DeltaTimer)
        If showKeyboard
            EnableKeyboard()
        Else
            DisableKeyboard()
        End

        If active And handler
            ProcessKeys()
        Else
            Reset()
        End
    End

    Private

    Method DisableKeyboard:Void()
        If Not keyboardEnabled Then Return
        keyboardEnabled = False

        input.DisableKeyboard()
    End

    Method EnableKeyboard:Void()
        If keyboardEnabled Then Return
        keyboardEnabled = True

        input.EnableKeyboard()
    End

    Method Reset:Void()
        If Not dirty Then Return
        dirty = False

        For Local i:Int = 0 Until lastMode.Length()
            lastMode[i] = False
        End
    End

    Method ProcessKeys:Void()
        Local mode:Bool
        dirty = True

        For Local i:Int = 0 Until lastMode.Length()
            mode = (KeyDown(i) = 1)

            If mode = lastMode[i]
                If mode Then DispatchEvent(i, PRESS)
{'fraction_non_alphanumeric': 0.060556464811783964, 'fraction_numerical': 0.005891980360065467, 'mean_word_length': 2.0049164208456243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '105070', 'n_tokens_mistral': 866, 'n_tokens_neox': 840, 'n_words': 256}