Spacenavigator: emulate Ctrl-Key by Spacenav-button

A forum for research and development of the user interface of FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
baschdl-ka
Posts: 5
Joined: Fri Nov 30, 2018 10:58 am

Spacenavigator: emulate Ctrl-Key by Spacenav-button

Post by baschdl-ka »

Hello,

I'm new to this Forum and use Freecad on Xubuntu 18.10. I used it on 18.04 and 16.04 before. The function i'm looking for worked neither FreeCad 0.16 nor 0.17.

Im trying to map the Buttons of my Spacenavigator on application level to key-presses of the keyboard, as mentioned above i'd like to emulate the Ctrl key by pressing one of the Spacenavigator Buttons. I tried to do this using macros but i didn't get it work. are there any other solutions.

Greetings from Karlsruhe, Germany

Sebastian (baschdl-ka)
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Spacenavigator: emulate Ctrl-Key by Spacenav-button

Post by wmayer »

When looking at the source code then SpaceNavigator is basically supported but not yet to map its keys.
Have a look at: https://github.com/FreeCAD/FreeCAD/blob ... 32.cpp#L55

To support it we would need a structure like this: https://github.com/FreeCAD/FreeCAD/blob ... 2.cpp#L109
baschdl-ka
Posts: 5
Joined: Fri Nov 30, 2018 10:58 am

Re: Spacenavigator: emulate Ctrl-Key by Spacenav-button

Post by baschdl-ka »

It is already possible to map the keys!
(via Menu: "Tool" "Customize" "Spaceball Buttons")
But there it is only possible to map "internal freecad functions" like "view xy", macro etc. to the two buttons

I like to map the ctrl-key to one of the two buttons to select multible parts and this is no options in the customization-menu.

greetings,
baschdl-ka
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Spacenavigator: emulate Ctrl-Key by Spacenav-button

Post by wmayer »

I like to map the ctrl-key to one of the two buttons to select multible parts and this is no options in the customization-menu.
As already said I think it's a matter of providing the needed e3dmouse_virtual_key structure so that the function HidToVirtualKey does something useful. At the moment it seems to do the mapping only for SpaceMouseWireless, SpaceMousePro, SpaceExplorer and SpacePilot.

Since I don't have such a device there is nothing I can do on it.
baschdl-ka
Posts: 5
Joined: Fri Nov 30, 2018 10:58 am

Re: Spacenavigator: emulate Ctrl-Key by Spacenav-button

Post by baschdl-ka »

Sorry, i'm not very familiar with devolping software so i know nothing about what is done i those files you linked above.
And very sorry it seems that i named my device wrong,! it is a 3dconnexion spacemouse (the blue glowing puck with two buttons)

As i mentioned it is possible to map functions to the buttons but no virtual-keys.

Sorry here the same in German, but a little bit more precise:

Hi, Entschuldigt bitte, mein Englisch ist zu sehr eingerostet um all das zu beschreiben was ich sagen möchte.
Ich kann auf die von mir leider bislang falsch bezeichnete SpaceMouse (der blau leuchtende Puck mit nur zwei Taste) bereits Funktionen aus den normalen FreeCAD Menüs zuordnen, nur leider keine virtuellen Tasten. Was wmayer mit den beiden verlinkten Dateien ausdrücken will erschließt sich mir leider aus Programmier-Unkenntnis nicht.
Ich habe das Gerät hier und im täglichen Einsatz, ich kann gerne (wenn mich jemand dabei unterstützt) die von wmayer oben verlinkten Dateien einmal anschauen, bearbeiten, ausprobieren was auch immer nötig ist um euch dabei zu unterstützen!

Ich liebe FreeCAD und wenn ich so einen kleinen Beitrag leisten kann ist mir das nur recht. Wie aber bereits gesagt hab ich sehr wenig Programmiererfahrung und bräuchte ggfs Anleitung bzw. Unterstützung.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Spacenavigator: emulate Ctrl-Key by Spacenav-button

Post by wmayer »

And very sorry it seems that i named my device wrong,! it is a 3dconnexion spacemouse (the blue glowing puck with two buttons)
I think SpaceNavigator is correct, at least it's listed as supported device.
Ich kann auf die von mir leider bislang falsch bezeichnete SpaceMouse (der blau leuchtende Puck mit nur zwei Taste) bereits Funktionen aus den normalen FreeCAD Menüs zuordnen, nur leider keine virtuellen Tasten.
Eventuell kann man diese Funktion erweitern, um die virtuellen Tasten auf Strg & Co zu mappen. Aber mangels Hardware kann ich das nicht wirklich beurteilen.
Was wmayer mit den beiden verlinkten Dateien ausdrücken will erschließt sich mir leider aus Programmier-Unkenntnis nicht.
Ich habe das Gerät hier und im täglichen Einsatz, ich kann gerne (wenn mich jemand dabei unterstützt) die von wmayer oben verlinkten Dateien einmal anschauen, bearbeiten, ausprobieren was auch immer nötig ist um euch dabei zu unterstützen!
Das Mappen der virtuellen Tasten wird zumindest für einige der Modelle so gemacht, wie in den obigen Links angegeben. Von daher kann ich mir vorstellen, dass man das mit dem SpaceNavigator auch so machen kann. Es wäre dann nur eine Frage, die richtige Reihenfolge bzw. die untstützten virtuellen Tasten zu ermitteln.

Vor einiger Zeit habe ich mich an einer rudimentären Unterstützung der Magellan-Maus versucht: https://forum.freecadweb.org/viewtopic.php?f=13&t=28306
Im Prinzip könnte man mit dem SpaceNavigator genauso verfahren, wobei das viel einfacher zu machen sein sollte. Alternativ kann auch jemand im Forum mit einem SpaceNavigator und Programmiererfahrung das bewerkstelligen. Beispielsweise haben tsadowski und ian.rees eine 3D-Maus, nur weiß nicht, welches Modell genau.
baschdl-ka
Posts: 5
Joined: Fri Nov 30, 2018 10:58 am

Re: Spacenavigator: emulate Ctrl-Key by Spacenav-button

Post by baschdl-ka »

Entschuldigt bitte die später Rückmeldung... Weihnachten Jahreswechsel, Geburtstage etc...

Prinzipiell lässt sich das ganze Mapping von Funktionen ja schon im Menü "Werkzeuge" - "Benutzerdefiniert" - Reiter: Spaceball-Knöpfe durchführen. nur eben keine Tasten. Wenn ich die bisherigen Vorschläge richtig verstehe geht es darum in den Dateien auf Code-Ebene die Tasten fix mit Funktionen zu verknüpfen, das finde ich eher unpraktisch - zumal wenn die eigentliche Menü-Struktur für die Verknüpfung schon angelegt ist und funktioniert. Ich habe bereits überlegt und versucht es über den Umweg eines Macros zu lösen, aber auch nicht zum Ziel gelangt
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Spacenavigator: emulate Ctrl-Key by Spacenav-button

Post by Jee-Bee »

baschdl-ka wrote: Wed Jan 23, 2019 8:44 pm Entschuldigt bitte die später Rückmeldung... Weihnachten Jahreswechsel, Geburtstage etc...

Prinzipiell lässt sich das ganze Mapping von Funktionen ja schon im Menü "Werkzeuge" - "Benutzerdefiniert" - Reiter: Spaceball-Knöpfe durchführen. nur eben keine Tasten. Wenn ich die bisherigen Vorschläge richtig verstehe geht es darum in den Dateien auf Code-Ebene die Tasten fix mit Funktionen zu verknüpfen, das finde ich eher unpraktisch - zumal wenn die eigentliche Menü-Struktur für die Verknüpfung schon angelegt ist und funktioniert. Ich habe bereits überlegt und versucht es über den Umweg eines Macros zu lösen, aber auch nicht zum Ziel gelangt
This is an English forum. So speak English or ask in one of the german topics
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Spacenavigator: emulate Ctrl-Key by Spacenav-button

Post by wmayer »

I again had a look at the source code and how events of a SpaceMouse are handled.
Im trying to map the Buttons of my Spacenavigator on application level to key-presses of the keyboard, as mentioned above i'd like to emulate the Ctrl key by pressing one of the Spacenavigator Buttons. I tried to do this using macros but i didn't get it work. are there any other solutions.
Apparently there are some 3dconnexion models that emulate the CTRL key. I assume that this already happens on driver level so that the OS and application receives a standard mouse button event. I don't know if SpaceNavigator is one of these models.

With the customize dialog where you can map a command to one of your buttons it's not possible to emulate a CTRL key. When FreeCAD receives a SpaceMouse button event it checks if a command is connected to this button and if yes executes it. That's the whole magic.

What is possible is to write a Python macro (using PySide) that creates an instance of QMouseEvent and sends it to the application or main window. There you can emulate that CTRL is pressed. However, the difficulty is how to determine the (cursor) position.

The code can looks like this:

Code: Select all

from PySide import QtCore
from PySide import QtGui

# FIXME: How to determine the position
x=...?
y=...?

mbp=QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, QtCore.QPoint(x,y), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.ControlModifier)
mbr=QtGui.QMouseEvent(QtCore.QEvent.MouseButtonRelease, QtCore.QPoint(x,y), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.ControlModifier)

mw=Gui.getMainWindow()
app=QtGui.qApp

view=mw.findChild(QtGui.QGraphicsView)
app.sendEvent(view, mbp)
app.sendEvent(view, mbr)
The next steps would be to create a macro in FreeCAD put inside the above code and then create a Macro command as wrapper for the macro file. This Macro command can then be used in the Space mouse settings to map one of the two buttons.
Dougl
Posts: 48
Joined: Thu Oct 01, 2020 6:08 pm

Re: Spacenavigator: emulate Ctrl-Key by Spacenav-button

Post by Dougl »

Has anyone been able to get this to work?
Doug
FreeCAD for Linux
Post Reply