convert procedure Vb to xojo

This vb procedure allows only desired characters to be entered in Text Field.
special function need to be rewritten in xojo, as shown below,

Private Sub txtHdeg_KeyPress(KeyAscii As Integer)
    
    If [b]KeyAscii[/b] = 47 Then
    Select Case Len(TxtHdeg.text)
        Case 1, 2, 4, 5
        Case Else
        KeyAscii = 0
    End Select
    Else
    If InStr(1, "0123456789" & [b]Chr$(vbKeyBack) & Chr$(vbKeySpace), Chr$(KeyAscii)[/b]) = 0 Then
      KeyAscii = 0
    End If
End Sub

Please check keydown event.
You may want to make a select case on asc(key) to return true for those you want to disallow.

FUNCTION KeyDown(key as string) as Boolean
 If AscB(key)=47 then 
    Select Case Len(TxtHdeg.text)
        Case 1, 2, 4, 5
            return false
        Case Else
            return true
    End Select
    Else
    If InStr(1, "0123456789" + ChrB(8) + ChrB(32), key) = 0 Then
     return false
    End If
    return true
End Function

[code] If AscB(key)=47 then

Select Case Len(TFhauteurdeg.text)
Case 1, 2, 4, 5
  return false
Case Else
  return true
End Select

Else
If InStr(1, “0123456789” + ChrB(8) + ChrB(32), key) = 0 Then
return true
End If
End If
return False[/code]

Under KeyDown event running properly, many thanks.