SpaceNavigator - Keyboard simulator

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

mmjc23
Posts: 15
Joined: Wed Dec 07, 2016 8:36 am

SpaceNavigator - Keyboard simulator

Post by mmjc23 »

Dear Sirs.

My company, bought a SpaceNavigator to be used as a PTT (Push To Talk) button.
Our application is capable of intercepting keyboard events even when it does not have focus and it uses Keyboard Key as PTT command.
The application can be configured in two modes
-the Keyboard key must be kept pressed to speak
-the first keyboard key click activates PTT and the second keyboard key click releases the PTT

So I would like to simulate the press (KeyPress, KeyDown, KeyUp events) of a Keyboard key (F13, for example) when Users press the middle SpaceNavigator sensor.
Is It possible with SpaceNavigator (even when the application isn't focused)?
Should I use the drivers and SDK to implement this feature or simply reprogram somehow the button?

Thank you very much and excuse me for english
Best Regards
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Re: SpaceNavigator - Keyboard simulator

Post by jwick »

You have two issues.

1) You want a consistent reaction all the time, regardless of which application is in focus. The driver is designed to follow keyboard focus. You have to disable this.
You have a few choices:
A) Write a program outside the driver that captures the data,
B) Write a program using our API that Grabs the device (this is going to prevent it from being used by other applications)
C) Write a cfg that tells the driver to call your DLL instead of handling the events itself. This can be done on a device-by-device basis. For example, the user could have a SN for PTT, but also a SpaceMouse* for 3D work.

In your code (DLL or API app) you can choose whatever communication mechanism you want. You may want to use SendInput to send an F13 to your kb hook, at least as a prototype. Sending kb events around does get messy, as system code gets involved determining where those go. I'd use a direct mechanism to communicate with your code.

2) You have specific requirements for push/release/push&hold, etc, that the driver may not have preimplemented the way you want. This points toward a B or C solution above.

I'd start out by making a cfg that sends F13 and see how that goes. You have to set <Grab>Hard</Grab> in the cfg to get the driver to never switch away from it. In fact, just modify the Desktop.xml to add an F13. Then you have a ButtonAction to switch to/from it.

I know I will have to answer a lot of questions on the details of everything I just wrote. Post here.

PTT is cool. And you could also use the twist axis to control volume, ...
mmjc23
Posts: 15
Joined: Wed Dec 07, 2016 8:36 am

Re: SpaceNavigator - Keyboard simulator

Post by mmjc23 »

Hello Jwick,

... and thank you very much for your answer
I did not understand much of what you wrote to me, but I want groped the approach with the configuration files.
Where can I find the documentation about the configuration files? I haven't found anything about it in "Start Menu\Programs\3Dconnexion\3DxWare SDK\Documentation\Online Doc" and "Start Menu\Programs\3Dconnexion\Documentation\Manuals\3DxWare Documentation".

When you are talking about "cfg" files, I assume you refer to "*.xml" files, is it correct?
I suppose that in "C:\Users\myuser\AppData\Roaming\3Dconnexion\3DxWare\Cfg" I can find settings for single O.S. user and in "C:\Program Files\3Dconnexion\3DxWare\3DxWinCore64\Cfg" I can find settings for all O.S. users.
Then, If I modify "C:\Program Files\3Dconnexion\3DxWare\3DxWinCore64\Cfg\Desktop.xml" with "<Grab>Hard</Grab>" (where???) all applications for all users will use "Desktop.xml" configuration. Is it correct?

Thank you again for your support
Best Regards
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Re: SpaceNavigator - Keyboard simulator

Post by jwick »

Our Cfg files are xml files with, typically an "AppCfg" outer element.
The defaults we ship are stored under ProgramFiles/.../3DxWinCore64/Cfg.
When you make a change with our GUI, your changes are stored in %APPDATA%/3Dconnexion/3DxWare/Cfg. Just your changes. The file inherits all the things you didn't change from a file in PF.
You should make your changes in AD.

Save this file into AD/.../3DxWare/Cfg/Desktop.xml:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<AppCfg Default="false" xmlns="" CfgFormatVersion="1.2" ThisFileVersion="1.2">
  <AppInfo>
    <Signature>
      <Name>STR_DESKTOP</Name>
      <Transport>KMJ</Transport>
      <ExecutableName>
      </ExecutableName>
    </Signature>
    <Options />
  </AppInfo>
  <CfgProperties>
    <InheritsFrom>STR_DESKTOP</InheritsFrom>
    <Grab>Hard</Grab>
  </CfgProperties>
</AppCfg>
This file will be locked in use by the driver. You can then use the GUI to make changes, like add F13 to a button.
mmjc23
Posts: 15
Joined: Wed Dec 07, 2016 8:36 am

Re: SpaceNavigator - Keyboard simulator

Post by mmjc23 »

Thank you jwick

I would like to simulate a keyboard key
It is it possible to change the "Desktop.xml" file, so it sends the key "F13" GLOBALLY (For Windows, all apps and all users) when Users press the middle SpaceNavigator sensor?

My application is already able to intercept the press of a key on the keyboard even when the application does not have focus; so I would like to simulate a "global" "F13" key when the user press SpaceNavigator Button.
We only use one 3DConnexion device (SpaceNavigator) for each computer for PTT function, then We do not need to diversify operations to be performed by device or by application launched.

Simply as a programmable USB Button like this: http://www.usbbutton.com/?gclid=CI2p-ci ... GwodPB4Lkg

Thank you
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Re: SpaceNavigator - Keyboard simulator

Post by jwick »

Try adding this to your Desktop.xml file:

Code: Select all

  
<AppCfg...>
   ...
  <Devices>
    <Device>
      <Name>SpaceNavigator</Name>
      <VendorID>46d</VendorID>
      <ProductID>c626</ProductID>
      <Axis>
        <Enabled>true</Enabled>
        <Input>
          <ActionID>HIDMultiAxis_Z</ActionID>
          <Min>0</Min>
          <Max>511</Max>
          <Deadband>200</Deadband>
        </Input>
        <Output>
          <ActionID>KB_Keystroke</ActionID>
          <RepeatStyle>PressAndHold</RepeatStyle>
          <KeyStroke>
            <Key>68</Key>
          </KeyStroke>
        </Output>
      </Axis>
    </Device>
  </Devices>
...
</AppCfg>
mmjc23
Posts: 15
Joined: Wed Dec 07, 2016 8:36 am

Re: SpaceNavigator - Keyboard simulator

Post by mmjc23 »

Thank you, Thank you very much jwick,

I have modified "Desktop.xml" file as you indicated to me. Now when I press SpaceNavigator sensor, it send "F13" key and my application intercepts it and goes in PTT.
I had to change the parameter "<AppCfg Default" to "true" to make sure that the SpaceNavigator sends "F13" key even if my application does not have focus

This is my Desktop.xml file:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<AppCfg Default="true" xmlns="" CfgFormatVersion="1.2" ThisFileVersion="1.2">
  <AppInfo>
    <Signature>
      <Name>STR_DESKTOP</Name>
      <Transport>KMJ</Transport>
      <ExecutableName>
      </ExecutableName>
    </Signature>
    <Options />
  </AppInfo>
  <CfgProperties>
    <InheritsFrom>STR_DESKTOP</InheritsFrom>
    <Grab>Hard</Grab>
  </CfgProperties>
  <Devices>
    <Device>
      <Name>SpaceNavigator</Name>
      <VendorID>46d</VendorID>
      <ProductID>c626</ProductID>
      <Axis>
        <Enabled>true</Enabled>
        <Input>
          <ActionID>HIDMultiAxis_Z</ActionID>
          <Min>0</Min>
          <Max>511</Max>
          <Deadband>200</Deadband>
        </Input>
        <Output>
          <ActionID>KB_Keystroke</ActionID>
          <RepeatStyle>PressAndHold</RepeatStyle>
          <KeyStroke>
            <Key>68</Key>
          </KeyStroke>
        </Output>
      </Axis>
    </Device>
  </Devices>
</AppCfg>
Now, only the "Sensor button" and "Left button" generate an action.
The Left Button, opens the 3dconnexion configuration tool again, so I have to figure out how disable it or re-configure as another key (i.e. "F14")
I saw that "f13" corresponds to "68"...Where can I find the correspondence between the Keyboard keys and their key codes?

Thank you in advance
Best regards
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Re: SpaceNavigator - Keyboard simulator

Post by jwick »

AppCfg Default=true/false depends on where you put the file. If it is in PF it needs to be true. If in AD false. But it is best to not modify the file in PF because they will get destroyed by the installer. If you want to ship your own default file, put it in %PROGRAMDATA%\3Dconnexion\3DxWare\Cfg.

68 is the HID code (hex) for the F13 button. It is easiest to just record the key on a device button and the GUI will write the code for you in your user cfg file. Since my kb doesn't have an F13, I looked it up in the HID Usage Table (http://www.usb.org/developers/hidpage/Hut1_12v2.pdf).

To unassign the Left Button, just assign the input to the output:

Code: Select all

<Device>
...
   <ButtonBank Default="true">
      <Name>STR_DEFAULT_BUTTONBANK</Name>
      <ID>Default</ID>
        <Button>
          <Input>
            <ActionID>HIDButton_1</ActionID>
          </Input>
          <Output>
            <ActionID>HIDButton_1</ActionID>
          </Output>
        </Button>
        <Button>
          <Input>
            <ActionID>HIDButton_2</ActionID>
          </Input>
          <Output>
            <ActionID>HIDButton_2</ActionID>
          </Output>
        </Button>
...
</Device>
mmjc23
Posts: 15
Joined: Wed Dec 07, 2016 8:36 am

Re: SpaceNavigator - Keyboard simulator

Post by mmjc23 »

Thank you jwick

Now, with your code, left and right buttons is disabled...Perfect!
I modified the Desktop.xml file in PF (Program files ??) folder so that it is applied to all O.S. users...I do not need to reinstall/update the drivers

Even Italian keyboards does not have the F13 key...for this reason I have reserved the F13-F24 keys to SpaceNavigator-MyApplication functions (Thank you for the HID codes list)

For testing purposes, I tried it to modify your code as shown below to set the F14 function to the left button but does not work.

Code: Select all

<ButtonBank Default="true">
      <Name>STR_DEFAULT_BUTTONBANK</Name>
      <ID>Default</ID>
        <Button>
          <Input>
            <ActionID>HIDButton_1</ActionID>
          </Input>
          <Output>
            <ActionID>KB_Keystroke</ActionID>
            <RepeatStyle>PressAndHold</RepeatStyle>
            <KeyStroke>
              <Key>69</Key>
            </KeyStroke>
          </Output>
        </Button>

Thank you very much again jwick
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Re: SpaceNavigator - Keyboard simulator

Post by jwick »

There is something not quite write with that Button syntax. Delete it and record a macro with the GUI. Then change the Key value to whatever F14 is from the HID usage table.

There is a chance the emulator does not handle F13+. I've never tested it.
mmjc23
Posts: 15
Joined: Wed Dec 07, 2016 8:36 am

Re: SpaceNavigator - Keyboard simulator

Post by mmjc23 »

I did some tests

It seems that the left and right buttons do not support "<ActionID>KB_Keystroke</ActionID>" (not only f13-f24)
In fact, if I set in the button Output "<ActionID>KB_Keystroke</ActionID>" and "<key>2C<key>" (Keyboard Spacebar) doesn't work, if I set "<ActionID>KB_Space</ActionID>", it works.

But this is not a solution because I do not have an "<ActionID>KB_F14</ActionID>" :cry:
mmjc23
Posts: 15
Joined: Wed Dec 07, 2016 8:36 am

Re: SpaceNavigator - Keyboard simulator

Post by mmjc23 »

Is it possible to have a list of ActionIDs?
How is it possible that there is no documentation about XML parameters?

Thank you in advance
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Re: SpaceNavigator - Keyboard simulator

Post by jwick »

It is best to use the GUI to program the buttons. If I change the assignment to my SN left button to F6, for example, I get this written into my user cfg file:

Code: Select all

  <MacroTable>
    <MacroEntry>
      <ID>F6</ID>
      <KeyStroke>
        <Key>3F</Key>
      </KeyStroke>
    </MacroEntry>
  </MacroTable>
  <Devices>
    <Device>
      <Name>SpaceNavigator</Name>
      <VendorID>46d</VendorID>
      <ProductID>c626</ProductID>
      <InheritsFrom>Standard 3D Mouse</InheritsFrom>
      <ButtonBank Default="true">
        <Name>STR_DEFAULT_BUTTONBANK</Name>
        <ID>Default</ID>
        <Button>
          <Input>
            <ActionID>HIDButton_1</ActionID>
          </Input>
          <Output>
            <ActionID>F6</ActionID>
          </Output>
        </Button>
      </ButtonBank>
    </Device>
  </Devices>
If you can't record F14 (no F14 on your kb), take this and change the F6s to F14s and the <Key> value from 3F to whatever the hex values is in the HID Usage Table. I still do not know if our KB emulator will send F13+ though.

There are many predefined ButtonActions in Base.xml that you are free to use. You can reference them by ID.
Documentation?! Why that would prevent me from changing things with the direction of the wind! :wink:
I never intended for people to be manually editing XML files, but that's another story.
mmjc23
Posts: 15
Joined: Wed Dec 07, 2016 8:36 am

Re: SpaceNavigator - Keyboard simulator

Post by mmjc23 »

PERFECT, PERFECT PERFECT!!!! jwick

Now, with the SpaceNavigator I can simulate the F13-F22 keys (used by my application), only by changing "Desktop.xml" file.

This is my final Desktop.xml file

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<AppCfg Default="true" xmlns="" CfgFormatVersion="1.2" ThisFileVersion="1.2">
  <AppInfo>
    <Signature>
      <Name>STR_DESKTOP</Name>
      <Transport>KMJ</Transport>
      <ExecutableName>
      </ExecutableName>
    </Signature>
    <Options />
  </AppInfo>
  <CfgProperties>
    <InheritsFrom>STR_DESKTOP</InheritsFrom>
    <Grab>Hard</Grab>
  </CfgProperties>
  <MacroTable>
    <MacroEntry>
      <ID>F21</ID>
      <KeyStroke>
        <Key>70</Key>
      </KeyStroke>
    </MacroEntry>
    <MacroEntry>
      <ID>F22</ID>
      <KeyStroke>
        <Key>71</Key>
      </KeyStroke>
    </MacroEntry>
  </MacroTable>
  <Devices>
    <Device>
      <Name>SpaceNavigator</Name>
      <VendorID>46d</VendorID>
      <ProductID>c626</ProductID>
      <Axis>
        <Enabled>true</Enabled>
        <Input>
          <ActionID>HIDMultiAxis_Z</ActionID>
          <Min>0</Min>
          <Max>511</Max>
          <Deadband>508</Deadband>
        </Input>
        <Output>
          <ActionID>KB_Keystroke</ActionID>
          <RepeatStyle>PressAndHold</RepeatStyle>
          <KeyStroke>
            <Key>68</Key>
          </KeyStroke>
        </Output>
      </Axis>
      <Axis>
        <Enabled>true</Enabled>
        <Input>
          <ActionID>HIDMultiAxis_Z</ActionID>
          <Min>-511</Min>
          <Max>0</Max>
          <Deadband>400</Deadband>
        </Input>
        <Output>
          <ActionID>KB_Keystroke</ActionID>
          <RepeatStyle>PressAndHold</RepeatStyle>
          <KeyStroke>
            <Key>69</Key>
          </KeyStroke>
        </Output>
      </Axis>
      <Axis>
        <Enabled>true</Enabled>
        <Input>
          <ActionID>HIDMultiAxis_RX</ActionID>
          <Min>0</Min>
          <Max>511</Max>
          <Deadband>400</Deadband>
        </Input>
        <Output>
          <ActionID>KB_Keystroke</ActionID>
          <RepeatStyle>PressAndHold</RepeatStyle>
          <KeyStroke>
            <Key>6A</Key>
          </KeyStroke>
        </Output>
      </Axis>
      <Axis>
        <Enabled>true</Enabled>
        <Input>
          <ActionID>HIDMultiAxis_RX</ActionID>
          <Min>-511</Min>
          <Max>0</Max>
          <Deadband>400</Deadband>
        </Input>
        <Output>
          <ActionID>KB_Keystroke</ActionID>
          <RepeatStyle>PressAndHold</RepeatStyle>
          <KeyStroke>
            <Key>6B</Key>
          </KeyStroke>
        </Output>
      </Axis>
      <Axis>
        <Enabled>true</Enabled>
        <Input>
          <ActionID>HIDMultiAxis_RZ</ActionID>
          <Min>0</Min>
          <Max>511</Max>
          <Deadband>400</Deadband>
        </Input>
        <Output>
          <ActionID>KB_Keystroke</ActionID>
          <RepeatStyle>PressAndHold</RepeatStyle>
          <KeyStroke>
            <Key>6C</Key>
          </KeyStroke>
        </Output>
      </Axis>
      <Axis>
        <Enabled>true</Enabled>
        <Input>
          <ActionID>HIDMultiAxis_RZ</ActionID>
          <Min>-511</Min>
          <Max>0</Max>
          <Deadband>400</Deadband>
        </Input>
        <Output>
          <ActionID>KB_Keystroke</ActionID>
          <RepeatStyle>PressAndHold</RepeatStyle>
          <KeyStroke>
            <Key>6D</Key>
          </KeyStroke>
        </Output>
      </Axis>
      <Axis>
        <Enabled>true</Enabled>
        <Input>
          <ActionID>HIDMultiAxis_X</ActionID>
          <Min>0</Min>
          <Max>511</Max>
          <Deadband>400</Deadband>
        </Input>
        <Output>
          <ActionID>KB_Keystroke</ActionID>
          <RepeatStyle>PressAndHold</RepeatStyle>
          <KeyStroke>
            <Key>6E</Key>
          </KeyStroke>
        </Output>
      </Axis>
      <Axis>
        <Enabled>true</Enabled>
        <Input>
          <ActionID>HIDMultiAxis_X</ActionID>
          <Min>-511</Min>
          <Max>0</Max>
          <Deadband>400</Deadband>
        </Input>
        <Output>
          <ActionID>KB_Keystroke</ActionID>
          <RepeatStyle>PressAndHold</RepeatStyle>
          <KeyStroke>
            <Key>6F</Key>
          </KeyStroke>
        </Output>
      </Axis>
      <ButtonBank Default="true">
      <Name>STR_DEFAULT_BUTTONBANK</Name>
      <ID>Default</ID>
        <Button>
          <Input>
            <ActionID>HIDButton_1</ActionID>
          </Input>
          <Output>
            <ActionID>F21</ActionID>
          </Output>
        </Button>
        <Button>
          <Input>
            <ActionID>HIDButton_2</ActionID>
          </Input>
          <Output>
            <ActionID>F22</ActionID>
          </Output>
        </Button>
      </ButtonBank>
    </Device>
  </Devices>
</AppCfg>

Thank you, Thank you very much jwick for your support
mmjc23
Posts: 15
Joined: Wed Dec 07, 2016 8:36 am

Re: SpaceNavigator - Keyboard simulator

Post by mmjc23 »

Unfortunately I have to reopen this thread...

With SpaceNavigator 3DX-600028 (3DX-700028), Drivers "10-5-12_r2890" and the Desktop.xml file described in this thread, my application is working properly.

Now, our customer has replaced a damaged SpaceNavigator 3dx-600028 with a new SpaceMouse 3DX-600053 (3dx-700059).
Is it the new version of the 3DX-600028?
So I installed the latest "10-6-3_r3045" drivers and replaced the "C:\Program files\3dconnexion\3DxWare\3DxWinCore64\Cfg\Desktop.xml" file with the one created in this thread...but it doesn't work

I noticed (on the Space Navigator utility trayicon tooltip) that the default file used by the new 3DX-600053 (or by the new drivers?) is "Explorer.xml" file instead of "Desktop.xml".
So I renamed "Explorer.xml" file (and restarted drivers) and the tooltip became "Desktop.xml". But it still doesn't work...the new 3dx does not simulate the "f13-f22" keys.

Why is the new 3dx not using the "Desktop.xml" file by default?
When and in what order are the files contained in the "C:\Program files\3dconnexion\3DxWare\3DxWinCore64\Cfg\" directory used?
Should I again understand how to modify the "Desktop.xml" (or "Explorer.xml"?) file for the new 3dx/drivers?
How is it possible that there is no guide or utility for customizing the keys by xml?

Thanks in advance
Best Regards
Post Reply