Added key-press actions.

master
Pacman Ghost 7 years ago
parent 9e6148e838
commit 1140a80fea
  1. 14
      MainApp/AppConfig.cs
  2. 36
      MouseDll/actions.cpp
  3. 67
      MouseDll/actions.hpp
  4. 2
      MouseDll/api.hpp

@ -88,11 +88,12 @@ namespace MouseInterception
{
public enum ActionType {
mouseLeft=1 , mouseRight=2 , mouseUp=3 , mouseDown=4 ,
wheelLeft=5 , wheelRight=6 , wheelUp=7 , wheelDown=8
wheelLeft=5 , wheelRight=6 , wheelUp=7 , wheelDown=8 ,
keyPress=10
}
public int mActionType ;
public int mActionParam ;
public int mKeyModifiers ;
public int mSpeed ;
}
public ApiAction[] mActions ;
public ApiAction[] actions { get { return mActions ; } }
@ -175,8 +176,15 @@ namespace MouseInterception
{
ApiAction action = new ApiAction() ;
action.mActionType = (int) Enum.Parse( typeof(ApiAction.ActionType) , actionXmlNode.Attributes["type"].Value , true ) ;
if ( action.mActionType == (int)ApiAction.ActionType.keyPress )
{
action.mActionParam = Utils.getXmlAttr( actionXmlNode , "vKey" , 0 ) ;
if ( action.mActionParam <= 0 )
throw new Exception( "Missing vKey." ) ;
}
else
action.mActionParam = Utils.getXmlAttr( actionXmlNode , "speed" , 0 ) ;
action.mKeyModifiers = getKeyModifiers( actionXmlNode ) ;
action.mSpeed = Utils.getXmlChildVal( actionXmlNode , "speed" , 0 ) ;
actions.Add( action ) ;
evt.mActionCount ++ ;
}

@ -7,8 +7,8 @@ using namespace std ;
// --- Action ---------------------------------------------------------
Action::Action( const ApiAction* pAction )
: mKeyModifiers( pAction->mKeyModifiers )
, mSpeed( pAction->mSpeed )
: mActionParam( pAction->mActionParam )
, mKeyModifiers( pAction->mKeyModifiers )
{
}
@ -27,6 +27,7 @@ Action::allocAction( const ApiAction* pAction )
case Action::atWheelRight: return new WheelRightAction(pAction) ;
case Action::atWheelUp: return new WheelUpAction(pAction) ;
case Action::atWheelDown: return new WheelDownAction(pAction) ;
case Action::atKeyPress: return new KeyPressAction(pAction) ;
default:
assert( false ) ;
return NULL ;
@ -38,7 +39,7 @@ Action::allocAction( const ApiAction* pAction )
int Action::adjustForSpeed( int val ) const
{
// NOTE: Speed values are percentages, offset by 100.
int percentDelta = 100 + speed() ;
int percentDelta = 100 + actionParam() ;
if ( percentDelta <= 0 )
percentDelta = 1 ; // nb: never go below 0%, always return something
return val * percentDelta / 100 ;
@ -54,8 +55,8 @@ Action::asString() const
buf << "<" << pActionName() ;
if ( keyModifiers() != 0 )
buf << ":" << keyModifiersString(keyModifiers()) ;
if ( speed() != 0 )
buf << ":" << speed() ;
if ( actionParam() != 0 )
buf << ":" << actionParam() ;
buf << ">" ;
return buf.str() ;
}
@ -63,7 +64,7 @@ Action::asString() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Action::keyModifiers() const { return mKeyModifiers ; }
int Action::speed() const { return mSpeed ; }
int Action::actionParam() const { return mActionParam ; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -258,3 +259,26 @@ WheelDownAction::doAction( void* pInfo , CSendInput* pSendInput ) const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const char* WheelDownAction::pActionName() const { return "WheelDownAction" ; }
// --- KeyPressAction -------------------------------------------------
KeyPressAction::KeyPressAction( const ApiAction* pAction )
: Action( pAction )
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void
KeyPressAction::doAction( void* pInfo , CSendInput* pSendInput ) const
{
// send a "keypress" event
int vKey = actionParam() ;
// FIXME! this will save/restore the keyboard state twice!
pSendInput->sendKeyboardInput( vKey , true , keyModifiers() ) ;
pSendInput->sendKeyboardInput( vKey , false , keyModifiers() ) ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const char* KeyPressAction::pActionName() const { return "KeyPressAction" ; }

@ -15,7 +15,8 @@ class Action
public:
enum eActionType {
atMouseLeft=1 , atMouseRight=2 , atMouseUp=3 , atMouseDown=4 ,
atWheelLeft=5 , atWheelRight=6 , atWheelUp=7 , atWheelDown=8
atWheelLeft=5 , atWheelRight=6 , atWheelUp=7 , atWheelDown=8 ,
atKeyPress=10
} ;
// constructors/destructor:
@ -31,8 +32,8 @@ public:
// access methods:
public:
int actionParam() const ;
int keyModifiers() const ;
int speed() const ;
virtual std::string asString() const ;
protected:
virtual const char* pActionName() const = 0 ;
@ -40,8 +41,8 @@ protected:
// data members:
private:
int mActionParam ;
int mKeyModifiers ;
int mSpeed ;
} ;
@ -61,59 +62,17 @@ std::ostream& operator<<( std::ostream& , const Action& ) ;
// ---------------------------------------------------------------------
class MouseLeftAction : public Action
{
DEFINE_ACTION_CLASS( MouseLeftAction ) ;
} ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class MouseRightAction : public Action
{
DEFINE_ACTION_CLASS( MouseRightAction ) ;
} ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class MouseLeftAction : public Action { DEFINE_ACTION_CLASS( MouseLeftAction ) ; } ;
class MouseRightAction : public Action { DEFINE_ACTION_CLASS( MouseRightAction ) ; } ;
class MouseUpAction : public Action { DEFINE_ACTION_CLASS( MouseUpAction ) ; } ;
class MouseDownAction : public Action { DEFINE_ACTION_CLASS( MouseDownAction ) ; } ;
class MouseUpAction : public Action
{
DEFINE_ACTION_CLASS( MouseUpAction ) ;
} ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class MouseDownAction : public Action
{
DEFINE_ACTION_CLASS( MouseDownAction ) ;
} ;
// ---------------------------------------------------------------------
class WheelLeftAction : public Action { DEFINE_ACTION_CLASS( WheelLeftAction ) ; } ;
class WheelRightAction : public Action { DEFINE_ACTION_CLASS( WheelRightAction ) ; } ;
class WheelUpAction : public Action { DEFINE_ACTION_CLASS( WheelUpAction ) ; } ;
class WheelDownAction : public Action { DEFINE_ACTION_CLASS( WheelDownAction ) ; } ;
class WheelLeftAction : public Action
{
DEFINE_ACTION_CLASS( WheelLeftAction ) ;
} ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class WheelRightAction : public Action
{
DEFINE_ACTION_CLASS( WheelRightAction ) ;
} ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class WheelUpAction : public Action
{
DEFINE_ACTION_CLASS( WheelUpAction ) ;
} ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class WheelDownAction : public Action
{
DEFINE_ACTION_CLASS( WheelDownAction ) ;
} ;
class KeyPressAction : public Action { DEFINE_ACTION_CLASS( KeyPressAction ) ; } ;
// ---------------------------------------------------------------------

@ -59,8 +59,8 @@ struct ApiEvent
struct ApiAction
{
int mActionType ;
int mActionParam ;
int mKeyModifiers ;
int mSpeed ;
} ;
// ---------------------------------------------------------------------

Loading…
Cancel
Save