C++ RealTimeStylusAPI derives coordinates that are ten times larger than the actual coordinates.

RL Chen 250 Reputation points
2024-11-21T13:15:05.9133333+00:00

In the following Packets in the RealTimeStylus API, I need to get the coordinates of the current input point on the screen. But strangely I found that this coordinate is normal for mouse input, while when it comes to finger and pen, the coordinate calculated by the same method is ten times bigger. I don't know why this is, and simply removing ten times results in the mouse coordinates being ten times smaller, which is clearly not the correct solution. What should I do, please and thank you.

STDMETHOD(Packets)(IRealTimeStylus* piRtsSrc, const StylusInfo* pStylusInfo, ULONG /*cPktCount*/, ULONG /*cPktBuffLength*/, LONG* pPacket, ULONG* /*pcInOutPkts*/, LONG** /*ppInOutPkts*/)
{
	FLOAT fInkToDeviceScaleX = 0.0f;
	FLOAT fInkToDeviceScaleY = 0.0f;
	ULONG ulPacketProperties = 0;
	PACKET_PROPERTY* pPacketProperties;
	piRtsSrc->GetPacketDescriptionData(pStylusInfo->tcid, &fInkToDeviceScaleX, &fInkToDeviceScaleY, &ulPacketProperties, &pPacketProperties);

	TouchMode mode{};
	for (int i = 0; i < ulPacketProperties; i++)
	{
		GUID guid = pPacketProperties[i].guid;

		if (guid == GUID_PACKETPROPERTY_GUID_X) mode.pt.x = LONG(pPacket[i] * fInkToDeviceScaleX + 0.5);
		else if (guid == GUID_PACKETPROPERTY_GUID_Y) mode.pt.y = LONG(pPacket[i] * fInkToDeviceScaleY + 0.5);
		else if (guid == GUID_PACKETPROPERTY_GUID_NORMAL_PRESSURE) mode.pressure = pPacket[i];
		else if (guid == GUID_PACKETPROPERTY_GUID_WIDTH) mode.touchWidth = pPacket[i];
		else if (guid == GUID_PACKETPROPERTY_GUID_HEIGHT) mode.touchHeight = pPacket[i];
	}

	std::unique_lock<std::shared_mutex> lock2(PointPosSm);
	TouchPos[TouchPointer[pStylusInfo->cid]] = mode;
	lock2.unlock();

	return S_OK;
}
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,666 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,774 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.