@@ -24,7 +24,7 @@ import {
2424 convertStringToCondition ,
2525 pwsh
2626} from '../powershell' ;
27- import { Enum , Key } from '../enums' ;
27+ import { ClickType , Enum , Key } from '../enums' ;
2828
2929const PLATFORM_COMMAND_PREFIX = 'windows:' ;
3030
@@ -359,7 +359,7 @@ export async function executeClick(this: NovaWindowsDriver, clickArgs: {
359359 elementId ?: string ,
360360 x ?: number ,
361361 y ?: number ,
362- button ?: 'left' | 'middle' | 'right' | 'back' | 'forward' , // TODO: add types
362+ button ?: ClickType ,
363363 modifierKeys ?: ( 'shift' | 'ctrl' | 'alt' | 'win' ) | ( 'shift' | 'ctrl' | 'alt' | 'win' ) [ ] , // TODO: add types
364364 durationMs ?: number ,
365365 times ?: number ,
@@ -368,7 +368,7 @@ export async function executeClick(this: NovaWindowsDriver, clickArgs: {
368368 const {
369369 elementId,
370370 x, y,
371- button = 'left' ,
371+ button = ClickType . LEFT ,
372372 modifierKeys = [ ] ,
373373 durationMs = 0 ,
374374 times = 1 ,
@@ -402,26 +402,14 @@ export async function executeClick(this: NovaWindowsDriver, clickArgs: {
402402 pos = [ x ! , y ! ] ;
403403 }
404404
405- let mouseButton : number ;
406- switch ( button . toLowerCase ( ) ) {
407- case 'left' :
408- mouseButton = 0 ;
409- break ;
410- case 'middle' :
411- mouseButton = 1 ;
412- break ;
413- case 'right' :
414- mouseButton = 2 ;
415- break ;
416- case 'back' :
417- mouseButton = 3 ;
418- break ;
419- case 'forward' :
420- mouseButton = 4 ;
421- break ;
422- default :
423- throw new errors . InvalidArgumentError ( 'Property button should be one of left, middle, right, back or forward.' ) ;
424- }
405+ const clickTypeToButtonMapping : { [ key in ClickType ] : number } = {
406+ [ ClickType . LEFT ] : 0 ,
407+ [ ClickType . MIDDLE ] : 1 ,
408+ [ ClickType . RIGHT ] : 2 ,
409+ [ ClickType . BACK ] : 3 ,
410+ [ ClickType . FORWARD ] : 4
411+ } ;
412+ const mouseButton : number = clickTypeToButtonMapping [ button ] ;
425413
426414 await mouseMoveAbsolute ( pos [ 0 ] , pos [ 1 ] , 0 ) ;
427415 for ( let i = 0 ; i < times ; i ++ ) {
0 commit comments