예제 #1
0
 static void Main(string[] args)
 {
     logger     = LogManager.GetLogger(typeof(Program));
     keysSounds = new KeysSoundEffects(logger, Resources.key1, Resources.key2, Resources.ctrl,
                                       Resources.shift, Resources.win, Resources.alt);
     try
     {
         configFilePath = "config.txt";
         config         = new JsonConfigSource(logger, configFilePath);
         hookService    = new GlobalHookService(logger, config, keysSounds, true);
         hookService.StartHookService();
         Application.Run();
         while (true)
         {
             if (System.Console.Read() == (int)Keys.Enter)
             {
                 hookService.StopHookService();
             }
         }
     }
     catch (Exception e)
     {
         logger.Error(e.StackTrace);
         System.Console.ReadKey();
     }
 }
예제 #2
0
 public GlobalHookService(ILog log, IConfigSource config, KeysSoundEffects soundEffects, bool keySoundOn = false)
 {
     Globals.IsSoundOn = keySoundOn;
     logger            = log;
     configSource      = config;
     keysSounds        = soundEffects;
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyboardHook" /> class.
 /// </summary>
 /// <param name="log"></param>
 /// <param name="combinationsConfiguration">The combinations configuration.</param>
 /// <param name="effects">The sounds effects.</param>
 /// <param name="helpWindow">Gui helper window</param>
 public KeyboardHook(ILog log, KeyCombinationsConfiguration combinationsConfiguration, KeysSoundEffects effects,
                     HelpWindow helpWindow = null)
 {
     logger                                = log;
     hookInstance                          = LoadPInvokeKernel32Library("User32");
     baseConfiguration                     = combinationsConfiguration;
     currentCombination                    = baseConfiguration.GetCombinationInstance(logger);
     combinationSize                       = baseConfiguration.CombinationSize;
     configCombinations                    = baseConfiguration.Combinations;
     lastUsedCombination                   = baseConfiguration.GetCombinationInstance(logger);
     combinationsKeysVirtualCodes          = configCombinations.ToVirtualKeyCodes().ToList();
     numericKeypadKeysVirtualCodes         = Globals.NumericKeypadVirtualKeyCodes.ToList();
     numericKeypadWithShiftKeyVirtualCodes = Globals.NumericKeypadWithShiftVirtualKeyCodes.ToList();
     numericKeysVirtualCodes               = Globals.NumericVirtualKeyCodes.ToList();
     modKeysVirtualCodes                   = Globals.ModKeysVirtualKeyCodes.ToList();
     KeysStateChecker                      = new WindowsInputDeviceStateAdaptor();
     inputSimulator                        = new InputSimulator();
     soundEffects                          = effects;
     helperWindow                          = helpWindow;
 }
예제 #4
0
        public MainWindow(ILog log)
        {
            InitializeComponent();
            logger                  = log;
            helperWindow            = new HelpWindow(logger);
            configFileName          = ConfigurationManager.AppSettings["DefaultConfigFileName"];
            Globals.AliasResources  = new ResXResourceSet(ConfigurationManager.AppSettings["KeyAliasesResxFileName"]);
            Globals.GlobalResources = new ResXResourceSet(ConfigurationManager.AppSettings["GlobalResxFileName"]);
            keysSounds              = new KeysSoundEffects(logger, Resources.Resources.key1, Resources.Resources.key2,
                                                           Resources.Resources.ctrl, Resources.Resources.shift, Resources.Resources.win,
                                                           Resources.Resources.alt);
            Globals.IsSoundOn = true;
            existingConfigs   = new List <string>();
            try
            {
                CollectExistingConfigs();
                if (!File.Exists(configFileName))
                {
                    configFileName = existingConfigs[0] ?? "";
                }

                if (existingConfigs.Any())
                {
                    config      = new JsonConfigSource(logger, configFileName);
                    hookService = new GlobalHookService(logger, config, keysSounds, true);
                }
                Helper.AddNumericRowsToGrid(combinationsTable);
            }
            catch (ArgumentOutOfRangeException outRangeException)
            {
                Helper.AddNumericRowsToGrid(combinationsTable);
                this.startAppBtn.Enabled   = false;
                this.stopAppBtn.Enabled    = false;
                this.EditConfigBtn.Enabled = false;
            }
            catch (Exception e)
            {
                logger.Error(e.StackTrace);
            }
        }