Reset the stroke history if we haven't seen anything for a while.

master
Pacman Ghost 7 years ago
parent 30698ac62a
commit d228399440
  1. 2
      MainApp/AppConfig.cs
  2. 46
      MainApp/Utils.cs
  3. 1
      MouseDll/api.hpp
  4. 2
      MouseDll/appProfile.cpp
  5. 2
      MouseDll/core.cpp
  6. 57
      MouseDll/core2.cpp
  7. 7
      MouseDll/deviceConfig.cpp
  8. 2
      MouseDll/deviceConfig.hpp

@ -51,6 +51,7 @@ namespace MouseInterception
public struct ApiDeviceConfig
{
public int mDeviceId ;
public int mStrokeHistoryResetInterval ;
public int mAppProfileStartIndex ;
public int mAppProfileCount ;
}
@ -148,6 +149,7 @@ namespace MouseInterception
{
ApiDeviceConfig deviceConfig = new ApiDeviceConfig() ;
deviceConfig.mDeviceId = Int32.Parse( deviceConfigXmlNode.Attributes["id"].Value ) ;
deviceConfig.mStrokeHistoryResetInterval = Utils.getXmlChildVal( deviceConfigXmlNode , "strokeHistoryResetInterval" , -1 ) ;
deviceConfig.mAppProfileStartIndex = appProfiles.Count ;
deviceConfig.mAppProfileCount = 0 ;
// parse the app profiles

@ -11,20 +11,50 @@ namespace MouseInterception
public static string getXmlChildVal( XmlNode xmlNode , string childNodeName , string defaultVal )
{
// get the child node's value
XmlNode childNode = xmlNode.SelectSingleNode( childNodeName ) ;
if ( childNode != null )
return childNode.InnerText.Trim() ;
return defaultVal ;
string val = getOptStringXmlChildVal( xmlNode , childNodeName ) ;
return (val != null) ? val : defaultVal ;
}
public static string getXmlChildVal( XmlNode xn , string s ) { return getXmlChildVal(xn,s,"") ; }
public static int getXmlChildVal( XmlNode xmlNode , string childNodeName , int defaultVal )
{
// get the child node's value
int? val = getOptIntXmlChildVal( xmlNode , childNodeName ) ;
return (val != null) ? (int)val : defaultVal ;
}
public static bool getXmlChildVal( XmlNode xmlNode , string childNodeName , bool defaultVal )
{
// get the child node's value
string val = getXmlChildVal( xmlNode , childNodeName , null ) ;
if ( val != null )
return Boolean.Parse( val ) ;
return defaultVal ;
bool? val = getOptBoolXmlChildVal( xmlNode , childNodeName ) ;
return (val != null) ? (bool)val : defaultVal ;
}
public static string getOptStringXmlChildVal( XmlNode xmlNode , string childNodeName )
{
// get the child node's value
XmlNode childNode = xmlNode.SelectSingleNode( childNodeName ) ;
if ( childNode != null )
return childNode.InnerText ;
return null ;
}
public static int? getOptIntXmlChildVal( XmlNode xmlNode , string childNodeName )
{
// get the child node's value
XmlNode childNode = xmlNode.SelectSingleNode( childNodeName ) ;
if ( childNode != null )
return Int32.Parse( childNode.InnerText ) ;
return null ;
}
public static bool? getOptBoolXmlChildVal( XmlNode xmlNode , string childNodeName )
{
// get the child node's value
XmlNode childNode = xmlNode.SelectSingleNode( childNodeName ) ;
if ( childNode != null )
return Boolean.Parse( childNode.InnerText ) ;
return null ;
}
public static string getXmlAttr( XmlNode xmlNode , string attrName , string defaultVal )

@ -21,6 +21,7 @@ struct ApiDevice
struct ApiDeviceConfig
{
int mDeviceId ;
int mStrokeHistoryResetInterval ;
int mAppProfileStartIndex ;
int mAppProfileCount ;
} ;

@ -19,7 +19,7 @@ AppProfile::AppProfile(
{
const ApiEvent* pEvent = pEvents + i ;
// validate the Action index/count
if ( pEvent->mActionStartIndex < 0 || pEvent->mActionStartIndex >= nActions )
if ( pEvent->mActionStartIndex < 0 || (pEvent->mActionStartIndex > 0 && pEvent->mActionStartIndex >= nActions) )
{
throw runtime_error(
MAKE_STRING(

@ -103,7 +103,7 @@ reloadConfig(
{
const ApiDeviceConfig* pDeviceConfig = pDeviceConfigs + i ;
// validate the AppProfile index/count
if ( pDeviceConfig->mAppProfileStartIndex < 0 || pDeviceConfig->mAppProfileStartIndex >= nAppProfiles )
if ( pDeviceConfig->mAppProfileStartIndex < 0 || (pDeviceConfig->mAppProfileStartIndex > 0 && pDeviceConfig->mAppProfileStartIndex >= nAppProfiles) )
{
throw runtime_error(
MAKE_STRING(

@ -4,19 +4,22 @@
using namespace std ;
typedef deque<InterceptionMouseStroke> InterceptionMouseStrokeDeque ;
typedef map< InterceptionDevice , InterceptionMouseStrokeDeque > InterceptionMouseStrokeHistory ;
typedef pair< DWORD , InterceptionMouseStroke > TimestampMouseStrokePair ;
typedef deque<TimestampMouseStrokePair> MouseStrokeHistory ;
typedef map< InterceptionDevice , MouseStrokeHistory > MouseStrokeHistoryTable ;
// --- LOCAL DATA ------------------------------------------------------
#define MAX_STROKE_HISTORY 20
#define DEFAULT_STROKE_HISTORY_RESET_INTERVAL 100 // milliseconds
#define DIRN_DETECT_WINDOW_SIZE 10
#define DIRN_DETECT_HORZ_BIAS 1.2 // FIXME! s.b. configurable
// local functions:
static void doRunMainLoop( int* pExitFlag ) ;
static bool detectDirn( const InterceptionMouseStrokeDeque* pStrokeHistory , eDirn* pDirn , int* pMagnitude ) ;
static bool findDevice( InterceptionDevice hDevice , Device** ppDevice ) ;
static bool detectDirn( const MouseStrokeHistory* pStrokeHistory , eDirn* pDirn , int* pMagnitude ) ;
static bool findDevice( InterceptionDevice hDevice , Device** ppDevice , DeviceConfig** ppDeviceConfig ) ;
// ---------------------------------------------------------------------
@ -72,13 +75,12 @@ doRunMainLoop( int* pExitFlag )
INTERCEPTION_FILTER_MOUSE_MOVE | INTERCEPTION_FILTER_MOUSE_WHEEL | INTERCEPTION_FILTER_MOUSE_HWHEEL
) ;
// initialize
InterceptionMouseStrokeHistory strokeHistory ;
// run the main loop
MouseStrokeHistoryTable strokeHistoryTable ;
for ( ; ; )
{
// wait for the next event
// NOTE: If the driver is not installed, this will return immediately :-/
InterceptionDevice hDevice = interception_wait_with_timeout( hContext , 200 ) ;
if ( hDevice == NULL )
{
@ -96,6 +98,7 @@ doRunMainLoop( int* pExitFlag )
// get the event
InterceptionMouseStroke* pStroke = (InterceptionMouseStroke*) &stroke ;
DWORD strokeTimestamp = GetTickCount() ;
int keyModifiers = 0 ;
if ( GetAsyncKeyState(VK_CONTROL) < 0 )
keyModifiers |= Event::kmCtrl ;
@ -130,7 +133,8 @@ doRunMainLoop( int* pExitFlag )
// find the device that generated the event
Device* pDevice ;
if ( ! findDevice( hDevice , &pDevice ) )
DeviceConfig* pDeviceConfig ;
if ( ! findDevice( hDevice , &pDevice , &pDeviceConfig ) )
{
// can't find the the device - check if we've seen it before
if ( gUnknownDevices.find( hDevice ) == gUnknownDevices.end() )
@ -157,8 +161,17 @@ doRunMainLoop( int* pExitFlag )
}
// record the stroke
InterceptionMouseStrokeDeque* pStrokeHistory = & strokeHistory[hDevice] ;
pStrokeHistory->push_back( *pStroke ) ;
// FIXME! only record mouse moves
MouseStrokeHistory* pStrokeHistory = & strokeHistoryTable[hDevice] ;
int strokeHistoryResetInterval = pDeviceConfig->strokeHistoryResetInterval() ;
if ( strokeHistoryResetInterval <= 0 )
strokeHistoryResetInterval = DEFAULT_STROKE_HISTORY_RESET_INTERVAL ;
if ( ! pStrokeHistory->empty() && (int)(strokeTimestamp-pStrokeHistory->back().first) >= strokeHistoryResetInterval )
{
// we haven't seen a move event for a while - reset the history
pStrokeHistory->clear() ;
}
pStrokeHistory->push_back( make_pair( strokeTimestamp , *pStroke ) ) ;
while ( pStrokeHistory->size() > MAX_STROKE_HISTORY )
pStrokeHistory->pop_front() ;
@ -181,7 +194,7 @@ doRunMainLoop( int* pExitFlag )
// ---------------------------------------------------------------------
static bool
detectDirn( const InterceptionMouseStrokeDeque* pStrokeHistory , eDirn* pDirn , int* pDirnMagnitude )
detectDirn( const MouseStrokeHistory* pStrokeHistory , eDirn* pDirn , int* pDirnMagnitude )
{
// check if we have enough stroke history
if ( pStrokeHistory->size() < DIRN_DETECT_WINDOW_SIZE )
@ -194,12 +207,12 @@ detectDirn( const InterceptionMouseStrokeDeque* pStrokeHistory , eDirn* pDirn ,
// FIXME! limit to left/right for h-wheel
LOG_CMSG( "dirnDetect2" , "DIRN DETECT: #=" << DIRN_DETECT_WINDOW_SIZE << "/" << pStrokeHistory->size() ) ;
int cumX=0 , cumY=0 , nStrokes=0 ;
for ( InterceptionMouseStrokeDeque::const_reverse_iterator it=pStrokeHistory->rbegin() ; it != pStrokeHistory->rend() ; ++it )
for ( MouseStrokeHistory::const_reverse_iterator it=pStrokeHistory->rbegin() ; it != pStrokeHistory->rend() ; ++it )
{
const InterceptionMouseStroke& stroke = *it ;
cumX += (*it).x ;
cumY += (*it).y ;
LOG_CMSG( "dirnDetect2" , " x=" << (*it).x << " ; y=" << (*it).y << " ; cum=" << cumX << "/" << cumY ) ;
const InterceptionMouseStroke& stroke = (*it).second ;
cumX += stroke.x ;
cumY += stroke.y ;
LOG_CMSG( "dirnDetect2" , " x=" << stroke.x << " ; y=" << stroke.y << " ; cum=" << cumX << "/" << cumY ) ;
if ( ++nStrokes >= DIRN_DETECT_WINDOW_SIZE )
break ;
}
@ -226,7 +239,7 @@ detectDirn( const InterceptionMouseStrokeDeque* pStrokeHistory , eDirn* pDirn ,
// ---------------------------------------------------------------------
static bool
findDevice( InterceptionDevice hDevice , Device** ppDevice )
findDevice( InterceptionDevice hDevice , Device** ppDevice , DeviceConfig** ppDeviceConfig )
{
// find the specified device
for( DeviceTable::iterator it=gDeviceTable.begin() ; it != gDeviceTable.end() ; ++it )
@ -235,8 +248,14 @@ findDevice( InterceptionDevice hDevice , Device** ppDevice )
// FIXME! have to check HID as well
if ( pDevice->deviceNumber() == hDevice )
{
*ppDevice = pDevice ;
return true ;
// found it - found the corresponding DeviceConfig
DeviceConfigTable::iterator it2 = gDeviceConfigTable.find( pDevice->deviceId() ) ;
if ( it2 != gDeviceConfigTable.end() )
{
*ppDevice = pDevice ;
*ppDeviceConfig = (*it2).second ;
return true ;
}
}
}
return false ;

@ -14,11 +14,14 @@ DeviceConfig::DeviceConfig(
{
// initialize the DeviceConfig
mDeviceId = pDeviceConfig->mDeviceId ;
mStrokeHistoryResetInterval = pDeviceConfig->mStrokeHistoryResetInterval ;
// initialize the DeviceConfig
for ( int i=0 ; i < nAppProfiles ; ++i )
{
const ApiAppProfile* pAppProfile = pAppProfiles + i ;
// validate the Event index/count
if ( pAppProfile->mEventStartIndex < 0 || pAppProfile->mEventStartIndex >= nEvents )
if ( pAppProfile->mEventStartIndex < 0 || (pAppProfile->mEventStartIndex > 0 && pAppProfile->mEventStartIndex >= nEvents) )
{
throw runtime_error(
MAKE_STRING(
@ -57,6 +60,7 @@ DeviceConfig::dumpDeviceConfig( ostream& os , const char* pPrefix ) const
pPrefix = "" ;
os << pPrefix << *this << ":" << endl ;
os << pPrefix << " deviceId = " << deviceId() << endl ;
os << pPrefix << " strokeHistoryResetInterval = " << strokeHistoryResetInterval() << endl ;
for ( AppProfilePtrVector::const_iterator it=appProfiles().begin() ; it != appProfiles().end() ; ++it )
(*it)->dumpAppProfile( os , MAKE_CSTRING(pPrefix << " ") ) ;
}
@ -74,4 +78,5 @@ operator<<( ostream& os , const DeviceConfig& deviceConfig )
// ---------------------------------------------------------------------
int DeviceConfig::deviceId() const { return mDeviceId ; }
const int DeviceConfig::strokeHistoryResetInterval() const { return mStrokeHistoryResetInterval ; }
const AppProfilePtrVector& DeviceConfig::appProfiles() const { return mAppProfiles ; }

@ -24,6 +24,7 @@ public:
// access methods:
public:
int deviceId() const ;
const int strokeHistoryResetInterval() const ;
const AppProfilePtrVector& appProfiles() const ;
// miscellaneous methods:
@ -33,6 +34,7 @@ public:
// data members:
private:
int mDeviceId ;
int mStrokeHistoryResetInterval ;
AppProfilePtrVector mAppProfiles ;
} ;

Loading…
Cancel
Save