@@ -404,7 +404,12 @@ static void processKeyboard()
404404
405405 platform .keyboard .state [tic_key_shift ] = mod & KMOD_SHIFT ;
406406 platform .keyboard .state [tic_key_ctrl ] = mod & (KMOD_CTRL | KMOD_GUI );
407+ platform .keyboard .state [tic_key_alt ] = mod & KMOD_LALT ;
407408 platform .keyboard .state [tic_key_capslock ] = mod & KMOD_CAPS ;
409+
410+ // it's weird, but system sends CTRL when you press RALT
411+ if (mod & KMOD_RALT )
412+ platform .keyboard .state [tic_key_ctrl ] = false;
408413 }
409414
410415 tic80_input * input = & tic -> ram .input ;
@@ -485,10 +490,14 @@ static void processTouchKeyboard()
485490 #include "kbdlayout.inl"
486491 };
487492
488- tic80_input * input = & platform .studio -> tic -> ram .input ;
493+ tic_mem * tic = platform .studio -> tic ;
494+
495+ tic80_input * input = & tic -> ram .input ;
489496
490497 s32 devices = SDL_GetNumTouchDevices ();
491498
499+ enum {BufSize = COUNT_OF (input -> keyboard .keys )};
500+
492501 for (s32 i = 0 ; i < devices ; i ++ )
493502 {
494503 SDL_TouchID id = SDL_GetTouchDevice (i );
@@ -510,13 +519,37 @@ static void processTouchKeyboard()
510519 pt .x /= scale ;
511520 pt .y /= scale ;
512521
513- for (s32 i = 0 ; i < COUNT_OF ( input -> keyboard . keys ) ; i ++ )
522+ for (s32 i = 0 ; i < BufSize ; i ++ )
514523 {
515524 tic_key * key = & input -> keyboard .keys [i ];
516525
517526 if (* key == tic_key_unknown )
518527 {
519528 * key = KbdLayout [pt .x / TIC_SPRITESIZE + pt .y / TIC_SPRITESIZE * Cols ];
529+ if (input -> keyboard .text == 0 )
530+ {
531+ static const char Symbols [] = " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ " ;
532+ static const char Shift [] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ)!@#$%^&*(_+{}|:\"~<>? " ;
533+
534+ enum {Count = sizeof Symbols };
535+
536+ for (s32 i = 0 ; i < TIC80_KEY_BUFFER ; i ++ )
537+ {
538+ tic_key key = tic -> ram .input .keyboard .keys [i ];
539+
540+ if (key > 0 && key < Count && tic -> api .keyp (tic , key , KEYBOARD_HOLD , KEYBOARD_PERIOD ))
541+ {
542+ bool caps = tic -> api .key (tic , tic_key_capslock );
543+ bool shift = tic -> api .key (tic , tic_key_shift );
544+
545+ input -> keyboard .text = caps
546+ ? key >= tic_key_a && key <= tic_key_z
547+ ? shift ? Symbols [key ] : Shift [key ]
548+ : shift ? Shift [key ] : Symbols [key ]
549+ : shift ? Shift [key ] : Symbols [key ];
550+ }
551+ }
552+ }
520553 break ;
521554 }
522555 }
@@ -734,6 +767,9 @@ static void handleKeydown(SDL_Keycode keycode, bool down)
734767 break ;
735768 }
736769 }
770+
771+ if (keycode == SDLK_AC_BACK )
772+ platform .keyboard .state [tic_key_escape ] = down ;
737773}
738774
739775static void pollEvent ()
@@ -742,7 +778,7 @@ static void pollEvent()
742778 tic80_input * input = & tic -> ram .input ;
743779
744780 input -> mouse .btns = 0 ;
745- tic -> ram . input . keyboard .text = 0 ;
781+ input -> keyboard .text = 0 ;
746782
747783 SDL_Event event ;
748784
0 commit comments