Skip to content

Instantly share code, notes, and snippets.

@bossbojo
Created May 23, 2019 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bossbojo/47f12a2b5c6f3eb21002855a066fdaf0 to your computer and use it in GitHub Desktop.
Save bossbojo/47f12a2b5c6f3eb21002855a066fdaf0 to your computer and use it in GitHub Desktop.
onChangeLang(char) {
if (char.key === '*') return;
const th_char = 'ๅ/-ภถุึคตจขชๆไำพะัีรนยบลฟหกดเ้่าสวงผปแอิืทมใฝ';
const en_char = '1234567890-=qwertyuiop[]asdfghjkl;\'zxcvbnm,./';
if (th_char.match(char.key)) {
this.Barcode = this.Barcode.substring(0, this.Barcode.length - 1);
for (let i = 0; i < th_char.length; i++) {
if (th_char[i] === char.key) {
this.Barcode += en_char[i];
return;
}
}
}
}
/*
<input type="text" class="form-control" id="Barcode" placeholder="รหัสบาร์โค้ด" name="Barcode"
[(ngModel)]="Barcode" (keypress)="onChangeLang($event)" (keyup)="onChangeLang($event)">
*/
@thanapongp
Copy link

onChangeLang($event: KeyboardEvent) {
    if ($event.key === '*') { return; }
    const code = $event.code;

    if (code.startsWith('Digit')) {
      ($event.target as any).value += code.split('Digit')[1];
      return false;
    }

    if (code.startsWith('Key')) {
      let char = code.split('Key')[1];

      if (!$event.shiftKey) {
        char = char.toLowerCase();
      }

      ($event.target as any).value += char;
      return false;
    }
  }

@bossbojo
Copy link
Author

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment