You can set up the stylus — or any other tracked target — to emulate the mouse. This can be useful if you are porting an existing application to zSpace. Basic setup requires the following steps:
The following partial code example illustrates this. Error handling is omitted for brevity. For the complete example, refer to the Mouse Emulation sample application in the Samples\Device subdirectory.
// zSpaceContext set during initialization. // ZSContext zSpaceContext = ...; // Get the stylus target. ZSHandle stylusHandle = NULL; zsFindTargetByType(zSpaceContext, ZS_TARGET_TYPE_PRIMARY, 0, &stylusHandle); // Set mouse emulation enabled. zsSetMouseEmulationEnabled(zSpaceContext, true); // Assign the target that will emulate the mouse. // In this case, we'll use the stylus to drive the mouse. zsSetMouseEmulationTarget(zSpaceContext, stylusHandle); // Map target buttons to mouse buttons. zsSetMouseEmulationButtonMapping(zSpaceContext, 0, ZS_MOUSE_BUTTON_LEFT); zsSetMouseEmulationButtonMapping(zSpaceContext, 1, ZS_MOUSE_BUTTON_RIGHT);
You can further refine mouse emulation by defining how far the target can be from the screen surface while emulating a mouse. This is useful if you want the stylus to behave as a stylus most of the time, but emulate a mouse when closer to the screen surface. Use the zsSetMouseEmulationMaxDistance() to specify a distance in meters.
You can also define a movement mode for mouse emulation. The movement mode, ZSMouseMovementMode, defines how the stylus and mouse control the pointer when both devices are used. By default, absolute positions are used, which means that both devices will attempt to control, or fight over, the pointer location. Use zsSetMouseEmulationMovementMode() to change to relative positions. In that case, any movement applied by mouse emulation is relative to the mouse's current position.