Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5206ff8

Browse files
authored
feat: --usb-non-blocking command line option (UltimateHackingKeyboard#1580)
* feat: --usb-driver command line option * feat: --usb-read-mode command line option * try to use device.setNonBlocking(true) * readSync * set non blocking * set non blocking commandline arg * style: revert undentation
1 parent d3d9394 commit 5206ff8

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

packages/uhk-agent/src/util/command-line.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const optionDefinitions: commandLineArgs.OptionDefinition[] = [
1010
{ name: 'preserve-udev-rules', type: Boolean },
1111
{ name: 'reenumerate-and-exit', type: String },
1212
{ name: 'spe', type: Boolean }, // simulate privilege escalation error
13-
{ name: 'usb-driver', type: String }
13+
{ name: 'usb-non-blocking', type: Boolean }
1414
];
1515

1616
export const options: CommandLineArgs = commandLineArgs(optionDefinitions, { partial: true }) as CommandLineArgs;
@@ -50,6 +50,10 @@ const sections: commandLineUsage.Section[] = [
5050
{
5151
name: 'spe',
5252
description: 'Simulate privilege escalation error'
53+
},
54+
{
55+
name: 'usb-non-blocking',
56+
description: 'Use USB non-blocking communication'
5357
}
5458
]
5559
}

packages/uhk-common/src/models/command-line-args.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ export interface CommandLineArgs {
2828
* simulate privilege escalation error
2929
*/
3030
spe?: boolean;
31+
/**
32+
* Use USB non-blocking communication
33+
*/
34+
'usb-non-blocking'?: boolean;
3135
}

packages/uhk-usb/src/uhk-hid-device.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ export class UhkHidDevice {
420420
return null;
421421
}
422422
const device = new HID(dev.path);
423+
if (this.options['usb-non-blocking']) {
424+
this.logService.misc('[UhkHidDevice] set non blocking communication mode');
425+
device.setNonBlocking(1 as any);
426+
}
423427
this.logService.misc('[UhkHidDevice] Used device:', JSON.stringify(dev, usbDeviceJsonFormatter));
424428
return device;
425429
} catch (err) {

packages/usb/src/command-line.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export const yargs = Yargs
1111
default: 'none',
1212
choices: ['all', 'config', 'misc', 'none', 'usb']
1313
})
14+
.option('usb-non-blocking', {
15+
description: 'Use USB non blocking communication',
16+
type: 'boolean',
17+
default: false
18+
})
1419
.help('help')
1520
.version(false)
1621
;

0 commit comments

Comments
 (0)