@@ -49,6 +49,59 @@ class Actions {
4949 [ DllImport ( "user32.dll" , SetLastError = true ) ]
5050 static extern void keybd_event ( byte bVk , byte bScan , int dwFlags , int dwExtraInfo ) ;
5151
52+ //Key Shortcut
53+ /*
54+ * Keys and how to convert
55+ * Each one on the left is accepted as a key inside the paramater
56+ */
57+ String [ , ] charactersType = new String [ , ] {
58+ { "BACKSPACE" , "{BACKSPACE}" } ,
59+ { "BREAK" , "{BREAK}" } ,
60+ { "CAPS_LOCK" , "{CAPSLOCK}" } ,
61+ { "DEL" , "{DELETE}" } ,
62+ { "DELETE" , "{DELETE}" } ,
63+ { "DOWN_ARROW" , "{DOWN}" } ,
64+ { "END" , "{END}" } ,
65+ { "ENTER" , "{ENTER}" } ,
66+ { "ESC" , "{ESC}" } ,
67+ { "HELP" , "{HELP}" } ,
68+ { "HOME" , "{HOME}" } ,
69+ { "INS" , "{INS}" } ,
70+ { "INSERT" , "{INSERT}" } ,
71+ { "LEFT_ARROW" , "{LEFT}" } ,
72+ { "NUM_LOCK" , "{NUMLOCK}" } ,
73+ { "PAGE_DOWN" , "{PGDN}" } ,
74+ { "PAGE_UP" , "{PGUP}" } ,
75+ { "PRINT_SCREEN" , "{PRTSC}" } ,
76+ { "RIGHT_ARROW" , "{RIGHT}" } ,
77+ { "SCROLL_LOCK" , "{SCROLLLOCK}" } ,
78+ { "TAB" , "{TAB}" } ,
79+ { "UP_ARROW" , "{UP}" } ,
80+ { "F1" , "{F1}" } ,
81+ { "F2" , "{F2}" } ,
82+ { "F3" , "{F3}" } ,
83+ { "F4" , "{F4}" } ,
84+ { "F5" , "{F5}" } ,
85+ { "F6" , "{F6}" } ,
86+ { "F7" , "{F7}" } ,
87+ { "F8" , "{F8}" } ,
88+ { "F9" , "{F9}" } ,
89+ { "F10" , "{F10}" } ,
90+ { "F11" , "{F11}" } ,
91+ { "F12" , "{F12}" } ,
92+ { "F13" , "{F13}" } ,
93+ { "F14" , "{F14}" } ,
94+ { "F15" , "{F15}" } ,
95+ { "F16" , "{F16}" } ,
96+ { "Keypad_add" , "{ADD}" } ,
97+ { "Keypad_subtract" , "{SUBTRACT}" } ,
98+ { "Keypad_multiply" , "{MULTIPLY}" } ,
99+ { "Keypad_divide" , "{DIVIDE}" } ,
100+ { "SHIFT" , "+" } ,
101+ { "CTRL" , "^" } ,
102+ { "ALT" , "%" }
103+ } ;
104+
52105 //Baisc things
53106 private void Error ( string errorMsg , string debugMsg = null ) {
54107 MainProgram . DoDebug ( "ERROR: " + ( String . IsNullOrEmpty ( debugMsg ) ? errorMsg : debugMsg ) ) ;
@@ -422,6 +475,75 @@ public void WriteOut(string parameter, string line) {
422475 successMessage = "Simulated writing \" " + writtenString + "\" " ;
423476 }
424477 }
478+
479+ public void KeyShortcut ( string parameter ) {
480+ /*
481+ * Added by : Joshua Miller
482+ * How to use it :
483+ * - To seperate keys please us '+' (to use '+' do {ADD})
484+ * - Things like ctrl will be converted to control key
485+ */
486+
487+ // Split up commands
488+ char splitChar = '+' ;
489+ String [ ] keyCombinationInput = parameter . Split ( splitChar ) ;
490+ // Will be added onto to make what to type
491+ String keyCombinationPress = "" ;
492+ // Put commands into correct form
493+ for ( int index = 0 ; index < keyCombinationInput . Length ; index ++ ) {
494+ // Get current command
495+ String command = keyCombinationInput [ index ] ;
496+ // If not empty
497+ if ( command != "" ) {
498+ // If one character (not command)
499+ if ( command . Length == 1 ) {
500+ // Add to the out
501+ keyCombinationPress = keyCombinationPress + command . ToLower ( ) ;
502+ }
503+ else {
504+ // If it is a command (probably)
505+ // Check if it is a possible command and needs to be changed
506+ bool foundYet = false ;
507+ for ( int countInCharacterArray = 0 ; countInCharacterArray < charactersType . GetLength ( 0 ) && foundYet == false ; countInCharacterArray ++ ) {
508+ String characterTestNow = charactersType [ countInCharacterArray , 0 ] ;
509+ if ( Equals ( command . ToUpper ( ) , characterTestNow ) ) {
510+ keyCombinationPress += charactersType [ countInCharacterArray , 1 ] ;
511+ foundYet = true ;
512+ } else if ( Equals ( command . ToUpper ( ) , charactersType [ countInCharacterArray , 1 ] ) ) {
513+ keyCombinationPress += charactersType [ countInCharacterArray , 1 ] ;
514+ foundYet = true ;
515+ }
516+ }
517+ if ( foundYet == false ) {
518+ MainProgram . DoDebug ( "KeyShortcut Action - Warning: A command " + command . ToUpper ( ) + " was not identified, please be weary as this may not work" ) ;
519+ MainProgram . DoDebug ( "KeyShortcut Action - Warning: Adding Anyway" ) ;
520+ keyCombinationPress += command ;
521+ }
522+ }
523+ } else {
524+ MainProgram . DoDebug ( "KeyShortcut Action - Warning: A character inside the paramater was blank" ) ;
525+ }
526+ }
527+
528+ // Is it testing?
529+ if ( MainProgram . testingAction ) {
530+ successMessage = ( "Simulated sending the combination: " + keyCombinationPress ) ;
531+ }
532+ else {
533+ // Try pressing keys
534+ bool keysPressedSuccess = true ;
535+ try {
536+ SendKeys . SendWait ( keyCombinationPress ) ;
537+ } catch ( ArgumentException ) {
538+ Error ( "Key combination is not valid" ) ;
539+ keysPressedSuccess = false ;
540+ }
541+ if ( keysPressedSuccess ) {
542+ successMessage = ( "Sending the combination: " + keyCombinationPress ) ;
543+ }
544+ }
545+ }
546+
425547 public void CreateFile ( string parameter ) {
426548 string fileLocation = parameter ;
427549 if ( ! File . Exists ( fileLocation ) ) {
0 commit comments