Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore keyboard shortcuts if "Alt" key is pressed #1451

Closed
PanierAvide opened this issue Oct 3, 2024 · 3 comments
Closed

Ignore keyboard shortcuts if "Alt" key is pressed #1451

PanierAvide opened this issue Oct 3, 2024 · 3 comments
Labels
Milestone

Comments

@PanierAvide
Copy link

Describe the bug

Original use case : be able to go forward/backward in browser history, using standard "Alt + LeftArrow" or "Alt + RightArrow" keyboard shortcut.

If I have a Viewer with keyboard: always option enabled, Left and Right Arrows are used for moving around the view. Pressing Alt key at the same time should avoid the camera move, and let browser do its thing. As now, viewer still moves around and browser doesn't do anything.

A special behaviour already exist for the Ctrl key, so I'm wondering if similar thing could be done for Alt key. If pressed, no basic key press would have effect, and keypress event goes up to browser.

Online demo URL

No response

Photo Sphere Viewer version

5.10.1

Plugins loaded

None

OS & browser

Linux, Firefox (but I guess it happens everywhere)

Additional context

Issue originating from Panoramax Web Viewer, where we wanted to be able to go forward/backward in history to go to previous shown image. I tried to work around PSV to not call PSV roll function if Alt is pressed. But at some point the keyboard event is intercepted and native browser forward/backward is never called.

Parts of code which almost work 😅

		const rollNoAlt = (action, opts) => (e => {
			console.log("roll", e);
			if(!this._altPressed) {
				console.log("no alt");
				this.psv.dynamics.position.roll(opts);
				this.psv.eventsHandler.keyHandler.down(action);
			}
		});
		try {
			this.psv = new Photo(this, this.psvContainer, {
				transitionDuration: this._options.transition,
				shouldGoFast: this._psvShouldGoFast.bind(this),
				keyboard: "always",
				keyboardActions: {
					...PSDefaults.keyboardActions,
					"8": rollNoAlt("ROTATE_UP", { pitch: false }),
					"2": rollNoAlt("ROTATE_DOWN", { pitch: true }),
					"6": rollNoAlt("ROTATE_RIGHT", { yaw: false }),
					"4": rollNoAlt("ROTATE_LEFT", { yaw: true }),
					"ArrowUp": rollNoAlt("ROTATE_UP", { pitch: false }),
					"ArrowDown": rollNoAlt("ROTATE_DOWN", { pitch: true }),
					"ArrowRight": rollNoAlt("ROTATE_RIGHT", { yaw: false }),
					"ArrowLeft": rollNoAlt("ROTATE_LEFT", { yaw: true }),
...

As it also happens on a classic, basic PSV viewer (if keyboard=always), I guess it makes sense to make this Alt behaviour handled mainstream.

@PanierAvide PanierAvide added the bug label Oct 3, 2024
@mistic100
Copy link
Owner

Going further, I think the default actions should be totally ignored if any modifier key is pressed, as in its current state keyboardActions keys cannot specify a mofifier.

Additionally I would add the original event to the custom callback parameters.

'ArrowUp': 'ROTATE_UP', // will move the view only and only if ArrowUp alone is pressed

'ArrowUp': (viewer, evt) => // will be called in ArrowUp is pressed with or without modifier, but the modifiers are accessible in the "evt"

@mistic100 mistic100 added this to the 5.10.2 milestone Oct 3, 2024
@PanierAvide
Copy link
Author

That was fast, thanks for your efficiency as always 😁

Copy link

This feature/bug fix has been released in version 5.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants