📄 ps2mouse.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
*/
#include <windows.h>
#include <ceddk.h>
#include <nkintr.h>
#include "ps2port.hpp"
#include "ps2mouse.hpp"
#include "ps2keybd.hpp"
#include "keybddbg.h"
DWORD dwSysIntr_Mouse;
BOOL
Ps2Mouse::
Initialize(
Ps2Port *pp2p
)
{
m_pp2p = pp2p;
m_hevInterrupt = NULL;
m_ui8ButtonState = 0;
m_cReportFormatLength = pp2p -> bIntelliMouseFound() ? 4 : 3;
return TRUE;
}
BOOL
Ps2Mouse::
IsrThreadProc(
void
)
{
int cBytes = 0;
UINT8 ui8Data;
INT8 buf[4];
long x,y;
long w = 0;
UINT8 ui8Buttons;
UINT8 ui8XorButtons;
unsigned int evfMouse;
DWORD dwTransferred = 0;
/*
HKEY hk;
DWORD dwStatus, dwSize, dwValue, dwType;
int iPriority = 249; // equivalent of THREAD_PRIORITY_HIGHEST
// look for our priority in the registry
dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\MOUSE"), 0, 0, &hk);
if(dwStatus == ERROR_SUCCESS) {
// get interrupt thread priority
dwSize = sizeof(dwValue);
dwStatus = RegQueryValueEx(hk, _T("Priority256"), NULL, &dwType, (LPBYTE) &dwValue, &dwSize);
if(dwStatus == ERROR_SUCCESS && dwType == REG_DWORD) {
iPriority = (int) dwValue;
}
// read our sysintr
dwSize = sizeof(dwValue);
dwStatus = RegQueryValueEx(hk, _T("SysIntr"), NULL, &dwType, (LPBYTE) &dwValue, &dwSize);
if(dwStatus == ERROR_SUCCESS) {
if(dwType == REG_DWORD) {
dwSysIntr_Mouse = dwValue;
} else {
dwStatus = ERROR_INVALID_PARAMETER;
}
}
RegCloseKey(hk);
}
if(dwStatus != ERROR_SUCCESS) {
goto leave;
}
CeSetThreadPriority(GetCurrentThread(), iPriority);
*/
/*
m_hevInterrupt = CreateEvent(NULL, FALSE, FALSE, NULL);
if ( m_hevInterrupt == NULL)
{
goto leave;
}
if ( !InterruptInitialize(dwSysIntr_Mouse, m_hevInterrupt, NULL, 0) )
{
goto leave;
}
*/
m_hevInterrupt=m_pp2p->GetDeviceEvent();
for ( ; ; )
{
wait_for_interrupt:
if (WaitForSingleObject(m_hevInterrupt, (cBytes == 0 ? INFINITE : IN_PACKET_TIMEOUT)) == WAIT_TIMEOUT)
{
DEBUGMSG(ZONE_MOUSEDATA,
(_T("%s: packet timeout, cBytes = %d\r\n"),
_T(__FILE__), cBytes));
cBytes = 0;
m_pp2p -> MouseDataRead(&ui8Data); // make sure mouse input buffer is empty
m_pp2p -> MouseDataRead(&ui8Data);
m_pp2p -> MouseDataRead(&ui8Data);
goto wait_for_interrupt;
}
if ( m_pp2p -> MouseDataRead(&ui8Data) )
{
DEBUGMSG(ZONE_MOUSEDATA,
(_T("%s: byte %d = 0x%02x\r\n"),
_T(__FILE__), cBytes, ui8Data));
if ( cBytes < m_cReportFormatLength )
{
buf[cBytes++] = ui8Data;
}
if ( cBytes == m_cReportFormatLength )
{
evfMouse = 0;
ui8XorButtons = buf[0] ^ m_ui8ButtonState;
if ( ui8XorButtons )
{
ui8Buttons = buf[0];
if ( ui8XorButtons & 0x01 )
{
if ( ui8Buttons & 0x01 )
{
evfMouse |= MOUSEEVENTF_LEFTDOWN;
}
else
{
evfMouse |= MOUSEEVENTF_LEFTUP;
}
}
if ( ui8XorButtons & 0x02 )
{
if ( ui8Buttons & 0x02 )
{
evfMouse |= MOUSEEVENTF_RIGHTDOWN;
}
else
{
evfMouse |= MOUSEEVENTF_RIGHTUP;
}
}
if ( ui8XorButtons & 0x04 )
{
if ( ui8Buttons & 0x04 )
{
evfMouse |= MOUSEEVENTF_MIDDLEDOWN;
}
else
{
evfMouse |= MOUSEEVENTF_MIDDLEUP;
}
}
m_ui8ButtonState = buf[0];
}
if ( buf[1] || buf[2] )
{
evfMouse |= MOUSEEVENTF_MOVE;
}
x = buf[1];
y = -buf[2];
// If IntelliMouse present buf[3] contains the relative displacement of the mouse wheel
if( m_pp2p -> bIntelliMouseFound() && buf[3])
{
evfMouse |= MOUSEEVENTF_WHEEL;
// we need to scale by WHEEL_DELTA = 120
w = -buf[3] * 120;
}
mouse_event(evfMouse, x, y, w, NULL);
cBytes = 0;
}
}
else
{
ERRORMSG(1,(TEXT("Error reading mouse data\r\n")));
}
InterruptDone(dwSysIntr_Mouse);
}
//leave:
return TRUE;
}
DWORD
Ps2MouseIsrThread(
Ps2Mouse *pp2m
)
{
pp2m -> IsrThreadProc();
return 0;
}
BOOL
Ps2Mouse::
IsrThreadStart(
void
)
{
HANDLE hthrd;
hthrd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Ps2MouseIsrThread, this, 0, NULL);
// Since we don't need the handle, close it now.
CloseHandle(hthrd);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -