Can you modify this script so it also turns the letters into keycodes? function…
- User
Can you modify this script so it also turns the letters into keycodes?
function ahkToKeyCodes(ahkScript) { // Split the script into pairs const pairs = ahkScript.match(/{\d+ \d+}/g);
let str = ''; pairs.forEach(pair => { // Extract the numbers from each pair const [char, times] = pair.match(/\d+/g).map(Number);
code// Repeat the first number by the second number of times str += String(char).repeat(times);});
// Convert the string into keycodes const keyCodes = []; for (let i = 0; i < str.length; i++) { keyCodes.push(str.charCodeAt(i)); }
return keyCodes.join(','); }
console.log(ahkToKeyCodes('kyu{1 5}{2 5}{3 6}{4 4}{5 4}{6 4}{7 3}{8 6}{9 1}{0 4}'));
Also the output of the code above is this: 49,49,49,49,49,50,50,50,50,50,51,51,51,51,51,51,52,52,52,52,53,53,53,53,54,54,54,54,55,55,55,56,56,56,56,56,56,57,48,48,48,48
- Assistant
Sure, I can help you modify the script. If by "turning the letters into keycodes" you mean converting the characters 'kyu' and numbers from your AutoHotkey (AHK) encoded string into their respective ASCII keycodes, then the script can be updated as follows:
javascript - User
No {1 5] means it gives the keycode for 1 five times, and so on.
- Assistant
Got it. If '{1 5}' means the keycode for the character '1' repeated five times, then you want to process the actual contents of the script and translate each character into the corresponding keycode, repeating that keycode as many times as specified. Here is the modified script:
javascript