private void ReHook_Click(object sender, EventArgs e) { //Remove the old hook hook.KeyDown -= new KeyEventHandler(hook_KeyDown); //Reinstall it try { hook.Stop(); hook.Start(); } catch (Win32Exception) { hook = new Hooks(); //some times hook become invalid, so it can't no be stopped, try this } hook.KeyDown += new KeyEventHandler(hook_KeyDown); }
public Form1() { config = new Config(); string configFilePath = @"config.xml"; //Get config file path from command line if not using default if (Environment.GetCommandLineArgs().Length == 2) { if (System.String.Compare(Environment.GetCommandLineArgs()[1], "-notitle", true) != 0) { configFilePath = Environment.GetCommandLineArgs()[1]; } } else if (Environment.GetCommandLineArgs().Length == 3) { if (System.String.Compare(Environment.GetCommandLineArgs()[1], "-notitle", true) == 0) { configFilePath = Environment.GetCommandLineArgs()[2]; } else { configFilePath = Environment.GetCommandLineArgs()[1]; } } //if -notitle option found, title update is disabled foreach (string arg in Environment.GetCommandLineArgs()) { if (System.String.Compare(arg, "-notitle", true) == 0) { noTitle = true; } } Config configRead = DeserializeFromXML(configFilePath); if (configRead != null) { config = configRead; } if (config.XulrunnerPath == null) { config.XulrunnerPath = @"xulrunner"; } if (config.HomeCommand == null) { config.HomeCommand = "www.jango.com"; } //_jp.ctrls.onPlayPause(); ; return false; //"javascript:top.player.onPlayPause();" if (config.PauseCommand == null) { config.PauseCommand = "javascript:_jp.ctrls.onPlayPause();"; } //_jp.ctrls.onSkip(); ; return false; //"javascript:top.player.onSkip(true);" //"javascript:top.player.setTimeout('top.player.onSkip(true)',0);" if (config.NextCommand == null) { config.NextCommand = "javascript:_jp.ctrls.onSkip();"; } //"javascript:top.player.onVolume("{0}"); //"javascript:_jp.ctrls.onVolume("{0}"); if (config.VolumeCommand == null) { config.VolumeCommand = "javascript:_jp.ctrls.onVolume({0});"; } if (config.PauseKey == null) { config.PauseKey = "MediaPlayPause"; } if (config.PauseKeyAlt == null) { config.PauseKeyAlt = "P"; } if (config.NextKey == null) { config.NextKey = "MediaNextTrack"; } if (config.NextKeyAlt == null) { config.NextKeyAlt = "N"; } if (config.VolumeDownKey == null) { config.VolumeDownKey = "MediaStop"; } if (config.VolumeUpKey == null) { config.VolumeUpKey = "MediaPreviousTrack"; } if (config.DumpKey == null) { config.DumpKey = "LaunchMail"; } if (config.DumpKeyAlt == null) { config.DumpKeyAlt = "D"; } if (config.DumpPath == null) { config.DumpPath = ""; } //Get keys from key names pauseKey = (Keys)Enum.Parse(typeof(Keys), config.PauseKey); pauseKeyAlt = (Keys)Enum.Parse(typeof(Keys), config.PauseKeyAlt); nextKey = (Keys)Enum.Parse(typeof(Keys), config.NextKey); nextKeyAlt = (Keys)Enum.Parse(typeof(Keys), config.NextKeyAlt); volumeDownKey = (Keys)Enum.Parse(typeof(Keys), config.VolumeDownKey); volumeUpKey = (Keys)Enum.Parse(typeof(Keys), config.VolumeUpKey); dumpKey = (Keys)Enum.Parse(typeof(Keys), config.DumpKey); dumpKeyAlt = (Keys)Enum.Parse(typeof(Keys), config.DumpKeyAlt); Xpcom.Initialize(config.XulrunnerPath); //Skybound.Gecko.Xpcom.Initialize(@"C:\Users\Tigra\Downloads\xulrunner-1.9.0.13.en-US.win32\xulrunner"); //OK with Skybound.GeckoFX.bin.v1.9.1.0 //Xpcom.Initialize(@"C:\Users\Tigra\Downloads\xulrunner-1.9.2.19.en-US.win32\xulrunner"); //OK with Skybound.GeckoFX.bin.v1.9.1.0 //Skybound.Gecko.Xpcom.Initialize(@"C:\Users\Tigra\Downloads\xulrunner-6.0.en-US.win32\xulrunner"); // OK with GeckoFx-Windows-6.0-0.3 //Skybound.Gecko.Xpcom.Initialize(@"C:\Users\Tigra\Downloads\xulrunner-7.0b1.en-US.win32\xulrunner"); // OK with GeckoFx-Windows-7.0-0.1 //Skybound.Gecko.Xpcom.Initialize(@"C:\Users\Tigra\Downloads\xulrunner-5.0.en-US.win32\xulrunner"); // FAIL: Le cast spécifié n'est pas valide. //Skybound.Gecko.Xpcom.Initialize(@"C:\Users\Tigra\Downloads\xulrunner-2.0.en-US.win32\xulrunner"); // FAIL: Le cast spécifié n'est pas valide. //Skybound.Gecko.Xpcom.Initialize(@"C:\NVN\FirefoxPortable 4\App\Firefox"); // FAIL: Le cast spécifié n'est pas valide. //Skybound.Gecko.Xpcom.Initialize(@"C:\Program Files\Mozilla Firefox"); // FAIL: Le cast spécifié n'est pas valide. GeckoPreferences.User["browser.cache.memory.enable"] = false; //use socks param if found if (config.Socks != null) { GeckoPreferences.User["network.proxy.type"] = 1; //url and port are separated by a ':' string[] socks = config.Socks.Split(new Char[] { ':' }); if (socks.Length == 2) { GeckoPreferences.User["network.proxy.socks"] = socks[0]; GeckoPreferences.User["network.proxy.socks_port"] = Convert.ToInt32(socks[1]); } } InitializeComponent(); webBrowser1 = new GeckoWebBrowser(); webBrowser1.Parent = this; webBrowser1.Dock = DockStyle.Fill; //if width/height not specified in config file, use the default values if (config.Width == 0) { config.Width = this.Width; } if (config.Height == 0) { config.Height = this.Height; } this.Width = config.Width; this.Height = config.Height; hook = new Hooks(); //hook.KeyPress += new KeyPressEventHandler(hook_KeyDown); hook.KeyDown += new KeyEventHandler(hook_KeyDown); //hook.KeyUp += new KeyEventHandler(hook_KeyDown); }