File tree Expand file tree Collapse file tree 4 files changed +39
-2
lines changed
Expand file tree Collapse file tree 4 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ <h1>Character key shortcuts</h1>
2121{
2222 "imports" : {
2323 "charKeyBookmarklet" : "../lib/characterKeyShortcuts.esm.marklet.js" ,
24+ "charCodeGenerator" : "../lib/util/charCodeGenerator.js" ,
2425 "ndf-bookmarklets" : "../index.js" ,
2526 "my-elements" : "https://nfreear.github.io/elements/i.js"
2627 } ,
@@ -33,10 +34,13 @@ <h1>Character key shortcuts</h1>
3334< script type ="module ">
3435 import 'my-elements' ;
3536 import { characterKeyShortcutsBookmarklet } from 'charKeyBookmarklet' ;
37+ import charCodeGenerator from 'charCodeGenerator' ;
3638
3739 const bookmarkletLinkElem = document . querySelector ( 'my-bookmarklet' ) ;
3840
3941 bookmarkletLinkElem . fromFunction ( characterKeyShortcutsBookmarklet ) ;
42+
43+ console . debug ( 'Generator:' , charCodeGenerator . prototype ) ;
4044</ script >
4145
4246</ html >
Original file line number Diff line number Diff line change 11/**
22 */
3+ import charCodeGenerator from './util/charCodeGenerator.js' ;
34import makeAsyncCharCodeIterator from './util/charCodeIterator.js' ;
45
56const { KeyboardEvent } = window ;
67
7- export async function characterKeyShortcuts ( ) {
8+ export function characterKeyShortcuts ( ) {
9+ [ ...charCodeGenerator ( ) ] . forEach ( async ( num ) => {
10+ console . log ( `>* ${ num } : ${ String . fromCharCode ( num ) } ` ) ;
11+ fireKBEvent ( 'keydown' , num ) ;
12+ fireKBEvent ( 'keypress' , num ) ;
13+ fireKBEvent ( 'keyup' , num ) ;
14+ await delay ( 20 ) ;
15+ } ) ;
16+ }
17+
18+ export async function characterKeyShortcutsIter ( ) {
819 const IT = makeAsyncCharCodeIterator ( ) ;
920 let RES = await IT . next ( ) ;
1021
@@ -17,6 +28,10 @@ export async function characterKeyShortcuts () {
1728 }
1829}
1930
31+ async function delay ( delayMs ) {
32+ return new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( ) , delayMs ) ) ;
33+ }
34+
2035export function fireKBEvent ( evName , num ) {
2136 const ev = new KeyboardEvent ( evName , {
2237 key : String . fromCharCode ( num ) ,
Original file line number Diff line number Diff line change 1010 */
1111export function characterKeyShortcutsBookmarklet ( ) {
1212 ( async ( ) => {
13- const MOD = await import ( '{__ORIGIN__}/lib/characterKeyShortcuts.js' ) ;
13+ const MOD = await import ( '{__ORIGIN__}/lib/characterKeyShortcuts.esm. js' ) ;
1414 const { characterKeyShortcuts } = MOD ;
1515 console . debug ( 'Character Key Shortcuts:' , MOD ) ;
1616 await characterKeyShortcuts ( ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * A character code generator.
3+ * 32 — 126 (inclusive),
4+ * 161 — 191 (inclusive),
5+ * 8364 (€)
6+ * @see https://jsdev.space/js-generators-guide/
7+ */
8+ export function * charCodeGenerator ( ) {
9+ for ( let i = 32 ; i < 127 ; i ++ ) {
10+ yield i ;
11+ }
12+ for ( let k = 161 ; k <= 191 ; k ++ ) {
13+ yield k ;
14+ }
15+ yield 8364 ;
16+ }
17+
18+ export default charCodeGenerator ;
You can’t perform that action at this time.
0 commit comments