@@ -123,19 +123,23 @@ export class InputHandler {
123123 Number . isFinite ( msg . dx ) &&
124124 Number . isFinite ( msg . dy )
125125 ) {
126- // Attempt ydotool relative movement first
127- const success = await moveRelative ( msg . dx , msg . dy )
128-
129- // Fallback to absolute positioning if ydotool is unavailable or fails
130- if ( ! success ) {
131- const currentPos = await mouse . getPosition ( )
132-
133- await mouse . setPosition (
134- new Point (
135- Math . round ( currentPos . x + msg . dx ) ,
136- Math . round ( currentPos . y + msg . dy ) ,
137- ) ,
138- )
126+ try {
127+ // Attempt ydotool relative movement first
128+ const success = await moveRelative ( msg . dx , msg . dy )
129+
130+ // Fallback to absolute positioning if ydotool is unavailable or fails
131+ if ( ! success ) {
132+ const currentPos = await mouse . getPosition ( )
133+
134+ await mouse . setPosition (
135+ new Point (
136+ Math . round ( currentPos . x + msg . dx ) ,
137+ Math . round ( currentPos . y + msg . dy ) ,
138+ ) ,
139+ )
140+ }
141+ } catch ( err ) {
142+ console . error ( "Move event failed:" , err )
139143 }
140144 }
141145 break
@@ -150,10 +154,16 @@ export class InputHandler {
150154 ? Button . RIGHT
151155 : Button . MIDDLE
152156
153- if ( msg . press ) {
154- await mouse . pressButton ( btn )
155- } else {
156- await mouse . releaseButton ( btn )
157+ try {
158+ if ( msg . press ) {
159+ await mouse . pressButton ( btn )
160+ } else {
161+ await mouse . releaseButton ( btn )
162+ }
163+ } catch ( err ) {
164+ console . error ( "Click event failed:" , err )
165+ // ensure release just in case
166+ await mouse . releaseButton ( btn ) . catch ( ( ) => { } )
157167 }
158168 }
159169 break
@@ -188,30 +198,35 @@ export class InputHandler {
188198
189199 case "scroll" : {
190200 const MAX_SCROLL = 100
191- const promises : Promise < void > [ ] = [ ]
201+ const promises : Promise < unknown > [ ] = [ ]
192202
193203 // Vertical scroll
194204 if ( this . isFiniteNumber ( msg . dy ) && Math . round ( msg . dy ) !== 0 ) {
195205 const amount = this . clamp ( Math . round ( msg . dy ) , - MAX_SCROLL , MAX_SCROLL )
196206 if ( amount > 0 ) {
197- promises . push ( mouse . scrollDown ( amount ) . then ( ( ) => { } ) )
207+ promises . push ( mouse . scrollDown ( amount ) )
198208 } else if ( amount < 0 ) {
199- promises . push ( mouse . scrollUp ( - amount ) . then ( ( ) => { } ) )
209+ promises . push ( mouse . scrollUp ( - amount ) )
200210 }
201211 }
202212
203213 // Horizontal scroll
204214 if ( this . isFiniteNumber ( msg . dx ) && Math . round ( msg . dx ) !== 0 ) {
205215 const amount = this . clamp ( Math . round ( msg . dx ) , - MAX_SCROLL , MAX_SCROLL )
206216 if ( amount > 0 ) {
207- promises . push ( mouse . scrollRight ( amount ) . then ( ( ) => { } ) )
217+ promises . push ( mouse . scrollRight ( amount ) )
208218 } else if ( amount < 0 ) {
209- promises . push ( mouse . scrollLeft ( - amount ) . then ( ( ) => { } ) )
219+ promises . push ( mouse . scrollLeft ( - amount ) )
210220 }
211221 }
212222
213223 if ( promises . length ) {
214- await Promise . all ( promises )
224+ const results = await Promise . allSettled ( promises )
225+ for ( const result of results ) {
226+ if ( result . status === "rejected" ) {
227+ console . error ( "Scroll event failed:" , result . reason )
228+ }
229+ }
215230 }
216231 break
217232 }
@@ -247,17 +262,26 @@ export class InputHandler {
247262 console . log ( `Processing key: ${ msg . key } ` )
248263 const nutKey = KEY_MAP [ msg . key . toLowerCase ( ) ]
249264
250- if ( nutKey !== undefined ) {
251- await keyboard . pressKey ( nutKey )
252- await keyboard . releaseKey ( nutKey )
253- } else if ( msg . key === " " || msg . key ?. toLowerCase ( ) === "space" ) {
254- const spaceKey = KEY_MAP . space
255- await keyboard . pressKey ( spaceKey )
256- await keyboard . releaseKey ( spaceKey )
257- } else if ( msg . key . length === 1 ) {
258- await keyboard . type ( msg . key )
259- } else {
260- console . log ( `Unmapped key: ${ msg . key } ` )
265+ try {
266+ if ( nutKey !== undefined ) {
267+ await keyboard . pressKey ( nutKey )
268+ await keyboard . releaseKey ( nutKey )
269+ } else if ( msg . key === " " || msg . key ?. toLowerCase ( ) === "space" ) {
270+ const spaceKey = KEY_MAP . space
271+ await keyboard . pressKey ( spaceKey )
272+ await keyboard . releaseKey ( spaceKey )
273+ } else if ( msg . key . length === 1 ) {
274+ await keyboard . type ( msg . key )
275+ } else {
276+ console . log ( `Unmapped key: ${ msg . key } ` )
277+ }
278+ } catch ( err ) {
279+ console . warn ( "Key press failed:" , err )
280+ // ensure release just in case
281+ if ( nutKey !== undefined )
282+ await keyboard . releaseKey ( nutKey ) . catch ( ( ) => { } )
283+ if ( msg . key === " " || msg . key ?. toLowerCase ( ) === "space" )
284+ await keyboard . releaseKey ( KEY_MAP . space ) . catch ( ( ) => { } )
261285 }
262286 }
263287 break
@@ -303,10 +327,13 @@ export class InputHandler {
303327 }
304328
305329 await new Promise ( ( resolve ) => setTimeout ( resolve , 10 ) )
330+ } catch ( err ) {
331+ console . error ( "Combo execution failed:" , err )
306332 } finally {
307- for ( const k of pressedKeys . reverse ( ) ) {
308- await keyboard . releaseKey ( k )
309- }
333+ const releasePromises = pressedKeys
334+ . reverse ( )
335+ . map ( ( k ) => keyboard . releaseKey ( k ) )
336+ await Promise . allSettled ( releasePromises )
310337 }
311338
312339 console . log ( `Combo complete: ${ msg . keys . join ( "+" ) } ` )
@@ -315,7 +342,11 @@ export class InputHandler {
315342
316343 case "text" :
317344 if ( msg . text && typeof msg . text === "string" ) {
318- await keyboard . type ( msg . text )
345+ try {
346+ await keyboard . type ( msg . text )
347+ } catch ( err ) {
348+ console . error ( "Failed to type text:" , err )
349+ }
319350 }
320351 break
321352 }
0 commit comments