B4A Library [B4X] SD CustomKeyboard (new version)

The CustomKeyboard library has made a leap in quality to be able to replace the native Android/iOs keyboard and also for the Desktop version.
Further developments are planned such as the possibility of adding editable fields from Design which are managed by this keyboard.

This required a more radical change, which is why I preferred to abandon the old thread and create a new thread where to insert this updated version, with new examples, avoiding creating confusion between the methods and suggestions given. The old version will remain but will no longer be supported


IMPORTANT
  • depends on SD CreativeBackGround (0.06+) library which must be downloaded
  • MaterialIcon font for special characters must be loaded. Use: SD_Keyboard1.SpecialKeyFont = xui.CreateMaterialIcons (16)


SD_CustomKeyboard

Author:
Star-Dust
Version: 2.03
  • CustomKey
    • Fields:
      • CodeCanc As Int
      • CodeDel As Int
      • CodeEnter As Int
      • CodeEraseAll As Int
      • CodeEsc As Int
      • CodeNext As Int
      • CodeShift As Int
      • CodeTab As Int
    • Functions:
      • AddCustomKeyToLastRow (UpperText As String, UpperCode As Int, LowerText As String, LowerCode As Int, size As Int, BackgroundKeyColor As Int, TextKeyColor As Int) As String
        Customize Key with color
        <code>Ck.AddCustomKeyToLastRow("SPACE",32,"SPACE.",32,3,xui.Color_Red,xui.Color_White) ' space large 3 key</code>
        <code>Ck.AddCustomKeyToLastRow("Enter",ck.CodeEnter,"Enter",ck.CodeEnter,1, ,xui.Color_Green,xui.Color_White))</code>
      • AddCustomKeyToLastRow2 (UpperText As String, UpperCode As Int, LowerText As String, LowerCode As Int, AlternateKeyUpper As Map, AlternateKeyLower As Map, size As Int, BackgroundKeyColor As Int, TextKeyColor As Int) As String
        Customize Key with color and alternative key
        <code>ck. AddCustomKeyToLastRow2("E",69,"e",101,CreateMap("È":200,"É":201),CreateMap("è":232,"é":233),1,,xui.Color_Red,xui.Color_White)</code>
      • AddEmptyRow As String
        Can add key with Add...LastRow
      • AddEmptySpaceToLastRow As String
      • AddKeyToLastRow (UpperText As String, UpperCode As Int, LowerText As String, LowerCode As Int, size As Int) As String
        Ck.AddKeytoLastRow("SPACE",32,"SPACE.",32,3) ' space large 3 key
        Ck.AddKeytoLastRow("",0,"",0,1) ' Empty
        Ck.AddKeytoLastRow("Enter",ck.CodeEnter,"Enter",ck.CodeEnter,1)
      • AddKeyToLastRow2 (UpperText As String, UpperCode As Int, LowerText As String, LowerCode As Int, AlternateKeyUpper As Map, AlternateKeyLower As Map, size As Int) As String
        To insert alternative key
        <code>Ck.AddKeyToLastRow2("E",69,"e",101,CreateMap("È":200,"É":201),CreateMap("è":232,"é":233),1)</code>
      • AddRow (Keys As List) As String
        CustomKey.AddRow(ListOfSingleKey)
      • AddSimpleCharToLastRow (Keys As String()) As String
        Char or key: Shift, Canc, Del, Tab, Esc, Next, EraseAll
        <code>CustomKey.AddSimpleCharToLastRow(array as string("A","B","C","Next","Tab","Canc"))</code>
        <code>CustomKey.AddSimpleCharToLastRow(Regex.Split(",","A,B,C,0,1,2,Enter"))</code>
      • AddSimpleCharToNewRow (Keys As String()) As String
        Special Char or key: Shift, Canc, Del, Tab, Esc, Next, EraseAll
        <code>CustomKey.AddRowSimpleChar(array as string("A","B","C","Next","Tab","Canc"))</code>
        <code>CustomKey.AddRowSimpleChar(Regex.Split(",","A,B,C,0,1,2,Enter"))</code>
      • AddStringtoKeyToNewRow (Strings As String()) As String
        Don't insert special char: Shift, Canc, Del, Tab, Esc, Next
        <code> CustomKey.AddStringtoKeyToNewRow(array as string("00","000","Hallo"))</code>
        <code> CustomKey.AddStringtoKeyToNewRow(Regex.Split(",","00,000,Hallo"))</code>
      • AddUpperLowerCharToLastRow (Keys As String()) As String
        Char or key: Shift, Canc, Del, Tab, Esc, Next,EraseAll
        CustomKey.AddUpperLowerCharToLastRow(array as string("Aa","Bb","Cc","Next","Tab","Canc"))
        CustomKey.AddUpperLowerCharToLastRow(Regex.Split(",","Aa,Bb,Cc,00,11,12,Enter"))
    • AddUpperLowerCharToNewRow (Keys As String()) As String
      Char or key: Shift, Canc, Del, Tab, Esc, Next,EraseAll
      <code>CustomKey.AddUpperLowerCharToNewRow(array as string("Aa","Bb","Cc","Next","Tab","Canc"))</code>
      <code>CustomKey.AddUpperLowerCharToNewRow(Regex.Split(",","Aa,Bb,Cc,00,11,12,Enter"))</code>
      • cEmptyKey As Type_SingleKey
      • cKey (UpperText As String, UpperCode As Int, LowerText As String, LowerCode As Int, AlternateUp As Map, AlternateLo As Map) As Type_SingleKey
      • cKeyCustomized (UpperText As String, UpperCode As Int, LowerText As String, LowerCode As Int, size As Int, BackgroundKeyColor As Int, TextKeyColor As Int, AlternateUp As Map, AlternateLo As Map) As Type_SingleKey
      • cKeySized (UpperText As String, UpperCode As Int, LowerText As String, LowerCode As Int, size As Int, AlternateUp As Map, AlternateLo As Map) As Type_SingleKey
      • Class_Globals As String
      • Initialize As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • KeyBoard As List
  • SD_Keyboard
    • Events:
      • Digit (Key As String)
      • DigitSpecialKey (Key As String)
    • Fields:
      • EventSender As Object
        InsertAlwaysAtEnd As Boolean
      • keyCanc As String
      • keyDel As String
      • keyEnter As String
      • keyEraseAll As String
      • keyNext As String
      • keyShiftDown As String
      • keyShiftLock As String
      • keyShiftUp As String
      • keyTab As String
      • Tag As Object
      • TimeLapseMilliSec As Int
    • Functions:
      • Class_Globals As String
      • ClearKeyboard As String
      • DesignerCreateView (Base As Object, Lbl As Label, Props As Map) As String
        Base type must be Object
      • DrawKeyboard (V As B4XView) As String
      • GetBase As B4XView
      • Initialize (Callback As Object, EventName As String) As String
      • Invalidate As String
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • SetEvent (View As EditText, te As TypeED) As String
      • SetKeyboard (TextEditorView As B4XView, NativeEventName As String, CustomizeKeyboard As CustomKey, ShiftOn As Boolean, NextFocus As B4XView) As String
      • SetupColor (BackgroundColorKey As Int, TextColorKey As Int, BackgroundColorBoard As Int) As String
      • ShifOn (S As Boolean) As String
      • ShiftStatus As Boolean
      • Snapshot As B4XBitmap
    • Properties:
      • DarkFactor As Float
        To set the intensity of the dark part of the shadow - normally = 0.85
      • Font
        Set Key Font
      • Height As Int
      • ImageBackground
      • KeyStyle
        0-Standard; 1-Comics; 2-Heart; 3-Flower; 4-Octagon
      • Left As Int
      • LightFactor As Float
        To set the intensity of the light part of the shadow - normally = 1.15
      • ShowKeyboard As Boolean
      • SpecialKeyFont
        Set Font of SpecilKey - Standard: MaterialIcon
      • Top As Int
      • Visible As Boolean
      • Width As Int

  • Rel. 2.01
    • Added event Digit and DigitSpecialKey
  • Rel. 2.02
    • The TextView Sender responds when an event is called from the virtual keyboard
  • Rel. 2.03
    • Fix tag bug
 

Attachments

  • SD_CustomKeyboard.zip
    32.9 KB · Views: 25
  • jSD_CustomKeyboard.zip
    28.1 KB · Views: 28
  • iSD_CustomKeyboard.zip
    337.3 KB · Views: 28
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
log release
  • 2.00
    • Method Add and Add2 changed to SetKeyboard
    • Method AddRowSimpleChar changed to AddSimpleCharToNewRow
    • Method AddRowDoubleChar changed to AddUpperLowerCharToNewRow
    • Method AddRowDoubleCharToLastRow changed to AddUpperLowerCharToLastRow
    • Method AddRowStringtoKey changed to AddStringtoKeyToNewRow
    • Added AddKeyToLastRow2 - Customize With Alternative
    • Added AddCustomKeyToLastRow2 - Key With Alternative
 

Star-Dust

Expert
Licensed User
Longtime User
SAMPLE 1 (B4XPAGE)
Simple numeric keyboard with special keys


SAMPLE 2 (B4XPAGE)
Classic keyboard


SAMPLE 3 (B4XPAGE)
Custom keyboard



SAMPLE 4 (B4XPAGE)
font bengali
 

Attachments

  • Sample1.zip
    15.7 KB · Views: 196
  • Sample2.zip
    15.4 KB · Views: 202
  • Sample3.zip
    15.7 KB · Views: 186
  • Sample4.zip
    205.8 KB · Views: 197
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
SAMPLE 5 (B4XPAGE)
Keyboard docked at the top left



SAMPLE 6 (B4XPAGE)
Personalized background with image


SAMPLE 7 (B4XPAGE)
SHIFT key used to change the entire keyboard



SAMPLE 8 (B4XPAGE)
Complete Keyboard
 

Attachments

  • Sample5.zip
    15.2 KB · Views: 192
  • Sample6.zip
    294.2 KB · Views: 187
  • Sample7.zip
    15.5 KB · Views: 174
  • Sample8.zip
    15.6 KB · Views: 201
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Is it possible to turn your smartphone into a PC keyboard?

I tried doing it with my keyboard and connecting it via the network... here's the result


I will provide the source of the example and an update of the library in the future
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
rel. 2.01 - Added event Digit and DigitSpecialKey

B4X:
Private Sub SD_Keyboard1_Digit(Key As String)
    If Key.Length=1 Then
        Log("Single Key: " & Asc(Key))
    Else
        Log("Group Key: " & Key)
    End If
End Sub

Private Sub SD_Keyboard1_DigitSpecialKey(Code As Int)
    Log("Special Code: " & Code)
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
Find attached an example to transform an Android smartphone into a PC keyboard. The code also works for iOS and with some modifications also as a mouse.
Communication between PC and mobile device occurs with broadcasting UDP packets.
The B4J App requires the jawtRobot library and launches Windows WordPad to illustrate how it can write to any third-party program after launching the B4J App
 

Attachments

  • jRemoteKeyboard.zip
    2.3 KB · Views: 57
  • aRemoteKeyboard.zip
    11.2 KB · Views: 53
Also found this old thread to use mobile as mouse through UDP, TCP and MQTT
 

Star-Dust

Expert
Licensed User
Longtime User
Release 2.02
  • Exposed the Sender of the TextView when an event is called from the virtual keyboard (EventSender)
B4X:
Private Sub TextField_EnterPressed
   Dim TextView As B4XView = SD_Keyboard1.EventSender
End Sub

Private Sub TextField_TextChanged (Old As String, New As String)
   Dim TextView As B4XView = SD_Keyboard1.EventSender
   Log("Change: " & Old & " " & New)
End Sub

Private Sub TextField_FocusChanged (HasFocus As Boolean)
    Dim TextView As B4XView = SD_Keyboard1.EventSender
    Log("Focus2: " & HasFocus)
End Sub

IMPORTANT
Don't use Sender to retrieve the TextView because it would return the keyboard class
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Release 2.03
  • Fixed old bugs on Tag