2222// SOFTWARE.
2323////////////////////////////////////////////////////////////////////////////////
2424
25+ using System ;
2526using System . IO ;
2627using System . Windows . Forms ;
2728using Support . UI ;
@@ -52,8 +53,9 @@ public enum OutputFlag
5253 Delay = 1 << 5 ,
5354 Toggle = 1 << 6 ,
5455 Down = 1 << 7 ,
55- Up = 1 << 8
56- //MAX = 1 << 32, // it's an int! (aka if you need 32 you'll need more space)
56+ Up = 1 << 8 ,
57+ // all ThreadKill ?
58+ // supports up to 32 entries
5759 }
5860
5961 public enum MouseButton
@@ -72,18 +74,17 @@ public enum MouseButton
7274 /// <param name="eKeyArgs">The input key arguments from user input</param>
7375 public OutputConfig ( int nFlags , byte byVirtualKey , int nParameter , KeyEventArgs eKeyArgs )
7476 {
75- #warning what's the chance of an input nFlags that is non-zero?
77+ Flags = nFlags ;
78+ VirtualKey = byVirtualKey ;
79+ Parameter = nParameter ;
80+
7681 if ( null != eKeyArgs )
7782 {
78- nFlags |=
83+ Flags |=
7984 ( eKeyArgs . Shift ? ( int ) OutputFlag . Shift : 0 )
8085 | ( eKeyArgs . Alt ? ( int ) OutputFlag . Alt : 0 )
8186 | ( eKeyArgs . Control ? ( int ) OutputFlag . Control : 0 ) ;
8287 }
83-
84- Flags = nFlags ;
85- VirtualKey = byVirtualKey ;
86- Parameter = nParameter ;
8788 }
8889
8990 /// <summary>
@@ -109,39 +110,53 @@ public OutputConfig(Stream zStream) : base(zStream) { }
109110 /// <returns>String representation of this definition</returns>
110111 public override string GetDescription ( )
111112 {
112- // mouse (every other flag ignored)
113- if ( IsFlaggedAs ( OutputFlag . MouseOut ) )
114- {
115- return "[" +
116- ( MouseButton ) VirtualKey +
117- getOutputDescriptionText ( "Mouse" ) +
118- ( IsFlaggedAs ( OutputFlag . Toggle ) ? "+Toggle" : string . Empty ) +
119- "]" ;
120- }
121113 // delay (every other flag ignored)
122114 if ( IsFlaggedAs ( OutputFlag . Delay ) )
123115 {
124- #warning todo: delay is currently not written to parameter
125116 return "[Delay: " + ( int ) Parameter + "]" ;
126117 }
118+
119+ if ( IsFlaggedAs ( OutputFlag . MouseOut ) )
120+ {
121+ return GetOutputDescriptionText ( ( MouseButton ) VirtualKey , "Mouse" ) ;
122+ }
123+
127124 // keyboard
128- return "[" +
129- ( Keys ) VirtualKey +
130- getOutputDescriptionText ( "Key" ) +
131- ( IsFlaggedAs ( OutputFlag . Shift ) ? "+Shift" : string . Empty ) +
132- ( IsFlaggedAs ( OutputFlag . Alt ) ? "+Alt" : string . Empty ) +
133- ( IsFlaggedAs ( OutputFlag . Control ) ? "+Control" : string . Empty ) +
134- ( IsFlaggedAs ( OutputFlag . Toggle ) ? "+Toggle" : string . Empty ) +
135- "]" ;
125+ return GetOutputDescriptionText ( ( Keys ) VirtualKey , "Key" ) ;
126+ }
127+
128+ /// <summary>
129+ /// Indicates if the config is assigned a valid action
130+ /// </summary>
131+ /// <returns></returns>
132+ public bool IsAssignedAction ( )
133+ {
134+ return IsFlaggedAs ( OutputFlag . Down )
135+ || IsFlaggedAs ( OutputFlag . Up )
136+ || IsFlaggedAs ( OutputFlag . MouseOut )
137+ || IsFlaggedAs ( OutputFlag . Delay )
138+ || IsFlaggedAs ( OutputFlag . DoNothing ) ;
136139 }
137140
138- private string getOutputDescriptionText ( string sPrefix )
141+ /// <summary>
142+ /// Gets the output description for the up/down/press based on the state of the flags
143+ /// </summary>
144+ /// <param name="sActionPrefix">The prefix indicating the type of input</param>
145+ /// <returns></returns>
146+ private string GetOutputDescriptionText ( Enum eInputId , string sActionPrefix )
139147 {
140- return ( IsFlaggedAs ( OutputFlag . Down ) && IsFlaggedAs ( OutputFlag . Up )
141- ? ":Press"
142- : ( ( IsFlaggedAs ( OutputFlag . Down ) ? ":{0}Down" . FormatString ( sPrefix ) : string . Empty ) +
143- ( IsFlaggedAs ( OutputFlag . Up ) ? ":{0}Up" . FormatString ( sPrefix ) : string . Empty ) )
144- ) ;
148+ return "[" +
149+ ( Keys ) VirtualKey +
150+ ( IsFlaggedAs ( OutputFlag . Down ) && IsFlaggedAs ( OutputFlag . Up )
151+ ? ":Press"
152+ : ( ( IsFlaggedAs ( OutputFlag . Down ) ? ":{0}Down" . FormatString ( sActionPrefix ) : string . Empty ) +
153+ ( IsFlaggedAs ( OutputFlag . Up ) ? ":{0}Up" . FormatString ( sActionPrefix ) : string . Empty ) )
154+ ) +
155+ ( IsFlaggedAs ( OutputFlag . Shift ) ? "+Shift" : string . Empty ) +
156+ ( IsFlaggedAs ( OutputFlag . Alt ) ? "+Alt" : string . Empty ) +
157+ ( IsFlaggedAs ( OutputFlag . Control ) ? "+Control" : string . Empty ) +
158+ ( IsFlaggedAs ( OutputFlag . Toggle ) ? "+Toggle" : string . Empty ) +
159+ "]" ;
145160 }
146161 }
147162}
0 commit comments