Private Sub txtb_KeyDown(txtb As Object, KeyCode, mask$, Optional letters As Boolean = False, Optional num As Boolean = False)
'Code PatrickToulon
'MsgBox KeyCode
Dim txt$, s&, longg&, plus&
If num = False And letters = False Then num = True
If txtb = "" And KeyCode <> 8 And KeyCode <> 46 Then txtb = mask
txt = txtb.Value: If txt = mask Then txtb.SelStart = 0
s = txtb.SelStart:
longg = txtb.SelLength: If longg = 0 Then longg = 1
plus = IIf(KeyCode < 96, 32, -48):
Select Case KeyCode
Case IIf(num = True, 96, 65) To IIf(num = True, 105, 90), IIf(letters = True, 65, 96) To IIf(letters = True, 90, 105)
If s = Len(mask) Then KeyCode = 0: Exit Sub
If Mid(mask, s + 1, 1) <> "x" Then KeyCode = 0: s = s + 1: txtb.SelStart = s: Exit Sub
Mid(txt, s + 1, longg) = IIf(Val(txtb.Tag) = 0, Chr(KeyCode + plus), UCase(Chr(KeyCode + plus))) & Mid(mask, s + 2, longg - 1): KeyCode = 0
txtb = txt: txtb.SelStart = IIf(InStr(1, txtb, "x") = 0, s + 1, InStr(1, txtb, "x") - 1)
Case 8
If s <> 0 Then Mid(txt, s, longg + 1) = Mid(mask, s, longg + 1) Else Exit Sub
txtb = txt: txtb.SelStart = s - 1: KeyCode = 0: If txt = mask Then txtb = ""
Case 46
If txtb = "" Then Exit Sub
If longg = 0 Then longg = 1
Mid(txt, s + 1, longg) = Mid(mask, s + 1, longg)
txtb = txt: txtb.SelStart = s: KeyCode = 0: If txt = mask Then txtb = ""
Case 39: txtb.SelStart = s + 1
Case 37: txtb.SelStart = s - IIf(s > 0, 1, 0)
Case 20: If Val(txtb.Tag) = 0 Then txtb.Tag = 1 Else txtb.Tag = 0
Case 16: txtb.Tag = 1
Case 13: ' touche enter fait ce que tu veux c'est la sortie
Case Else: KeyCode = 0
End Select
End Sub