Convert character in PHP to javascript event keycode

493 views Asked by At

What would be the process for converting basic alphanumeric character into javascript event key codes?

For example the letters sso would convert to 83, 83, 79


The idea is we've got a CMS field which somebody can enter a key sequence like hello, this is stored in a db which is retrieved by PHP and displayed in a variable via a php template.

Then in javascript we monitor the keypress event to check if that sequence is entered via a event listener.

So we need to be able convert the string into keycodes which we can monitor in the event.

I've tried using ord in like

$letters = str_split($str);
$sequence = array();
foreach ($letters as $letter) {
    $sequence[] = ord($letter);
}
dd($sequence);

but that produces

array:3 [▼
  0 => 115
  1 => 115
  2 => 111
]

So I assume thats just converting it to ASCII, how would we actually get the keycode value?

Thanks

0

There are 0 answers