From 83883821f4ddbf5acff5430ef5fe41f3446f4cd8 Mon Sep 17 00:00:00 2001 From: Josue Date: Wed, 14 Jul 2021 11:32:29 -0400 Subject: [PATCH] refactor(front-end): add all the key combinations specified in the specs --- striker-ui/components/Display/FullSize.tsx | 19 +++++++--- .../components/Display/keyCombinations.ts | 35 +++++++++++++------ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/striker-ui/components/Display/FullSize.tsx b/striker-ui/components/Display/FullSize.tsx index a0c267c9..0efd3a3b 100644 --- a/striker-ui/components/Display/FullSize.tsx +++ b/striker-ui/components/Display/FullSize.tsx @@ -73,9 +73,20 @@ const FullSize = ({ setMode }: PreviewProps): JSX.Element => { setAnchorEl(event.currentTarget); }; - const handleSendKeys = () => { + const handleSendKeys = (scans: string[]) => { if (rfb.current) { - rfb.current.sendCtrlAltDel(); + if (!scans.length) rfb.current.sendCtrlAltDel(); + else { + // Send pressing keys + scans.forEach((scan) => { + rfb.current.sendKey(scan, 1); + }); + + // Send releasing keys in reverse order + for (let i = scans.length - 1; i >= 0; i -= 1) { + rfb.current.sendKey(scans[i], 0); + } + } setAnchorEl(null); } }; @@ -118,10 +129,10 @@ const FullSize = ({ setMode }: PreviewProps): JSX.Element => { open={Boolean(anchorEl)} onClose={() => setAnchorEl(null)} > - {keyCombinations.map(({ keys }) => { + {keyCombinations.map(({ keys, scans }) => { return ( handleSendKeys(scans)} className={classes.keysItem} key={keys} > diff --git a/striker-ui/components/Display/keyCombinations.ts b/striker-ui/components/Display/keyCombinations.ts index 844e4be0..c06ad388 100644 --- a/striker-ui/components/Display/keyCombinations.ts +++ b/striker-ui/components/Display/keyCombinations.ts @@ -1,14 +1,27 @@ -const keyCombinations: Array<{ keys: string; scans: string }> = [ - { keys: 'Ctrl + Alt + Del', scans: 'Optimal' }, - { keys: 'Ctrl + Alt + F1', scans: 'Not Ready' }, - { keys: 'Ctrl + Alt + F2', scans: 'Not Ready' }, - { keys: 'Ctrl + Alt + F3', scans: 'Not Ready' }, - { keys: 'Ctrl + Alt + F4', scans: 'Not Ready' }, - { keys: 'Ctrl + Alt + F5', scans: 'Not Ready' }, - { keys: 'Ctrl + Alt + F6', scans: 'Not Ready' }, - { keys: 'Ctrl + Alt + F7', scans: 'Not Ready' }, - { keys: 'Ctrl + Alt + F8', scans: 'Not Ready' }, - { keys: 'Ctrl + Alt + F9', scans: 'Not Ready' }, +const ControlL = '0xffe3'; +const AltL = '0xffe9'; + +const F1 = '0xffbe'; +const F2 = '0xffbf'; +const F3 = '0xffc0'; +const F4 = '0xffc1'; +const F5 = '0xffc2'; +const F6 = '0xffc3'; +const F7 = '0xffc4'; +const F8 = '0xffc5'; +const F9 = '0xffc6'; + +const keyCombinations: Array<{ keys: string; scans: string[] }> = [ + { keys: 'Ctrl + Alt + Delete', scans: [] }, + { keys: 'Ctrl + Alt + F1', scans: [ControlL, AltL, F1] }, + { keys: 'Ctrl + Alt + F2', scans: [ControlL, AltL, F2] }, + { keys: 'Ctrl + Alt + F3', scans: [ControlL, AltL, F3] }, + { keys: 'Ctrl + Alt + F4', scans: [ControlL, AltL, F4] }, + { keys: 'Ctrl + Alt + F5', scans: [ControlL, AltL, F5] }, + { keys: 'Ctrl + Alt + F6', scans: [ControlL, AltL, F6] }, + { keys: 'Ctrl + Alt + F7', scans: [ControlL, AltL, F7] }, + { keys: 'Ctrl + Alt + F8', scans: [ControlL, AltL, F8] }, + { keys: 'Ctrl + Alt + F9', scans: [ControlL, AltL, F9] }, ]; export default keyCombinations;