I am new to RXJS and looking for a way to drag an HtmlElement when the user presses the space key and then drags the element with the mouse.
The dragging should be initiated by either pressing the SPACE key followed by a left click, or vice versa. The dragging will end when the SPACE key is released (keyup event) or when the mouse button is clicked (mouseup event), whichever happens first.
To implement this, I have created four observables for the specific events:
spaceDown$ = fromEvent<KeyboardEvent>(document, "keydown").pipe( filter(key => key.code === 'Space'))
spaceUp$ = fromEvent<KeyboardEvent>(document, "keyup").pipe( filter( key => key.code === 'Space'))
mouseDown$ = fromEvent<MouseEvent>(document, "mousedown").pipe( filter( mouse => mouse.button == 0))
mouseUp$ = fromEvent<MouseEvent>(document, "mouseup").pipe( filter( mouse => mouse.button == 0))
I have tried using operators like 'combineLatest', 'withLatestFrom', 'merge' on these streams but have not been able to achieve the desired behavior yet. Any suggestions on how to accomplish this?