private void selectedKeybinding_SelectedIndexChanged(object sender, EventArgs e) { current = bindings.bindings[selectedKeybinding.SelectedItem.ToString()]; Keybindings.Set(bindings); modifierShift.Checked = current.SHIFT; modifierCtrl.Checked = current.CTRL; modifierAlt.Checked = current.ALT; modifierSuper.Checked = current.SUPER; key.Text = current.Key.ToString(); }
public AdjustKeybindings(ref Keybindings keybindings) { InitializeComponent(); this.bindings = keybindings; foreach (string binding in keybindings.bindings.Keys) { selectedKeybinding.Items.Add(binding); } selectedKeybinding.SelectedIndex = 0; FormClosed += (a, b) => { Keybindings.Set(bindings); }; }
public KeydeemAppContext() { Program.Context = this; items["Exit"] = new MenuItem("Exit", Exit); items["Keybindings"] = new MenuItem("Adjust keybindings...", AdjKeybindings); icon = new NotifyIcon() { Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location), ContextMenu = new ContextMenu(items.Values.ToArray()), Text = "Keydeem - Logging in to Steam...", Visible = true }; icon.DoubleClick += (a, b) => { if (this.window != null) { this.window.Activate(); } else { this.window = new MainWindow(log); window.Show(); window.FormClosed += (c, d) => window = null; } }; keybindings = Keybindings.Get(new Dictionary <string, Keybinding> { { "Redeem Clipboard", new Keybinding(KeyModifier.Super | KeyModifier.Shift, Keys.R) }, { "Force Redeem Clipboard", new Keybinding(KeyModifier.Super | KeyModifier.Shift | KeyModifier.Control, Keys.R) } }); steam = new Steam(successfulLogon => { if (!successfulLogon) { Exit(null, null); return; } icon.Text = "Keydeem"; icon.ShowBalloonTip(0, "Logged on to Steam", "Press " + keybindings.bindings["Redeem Clipboard"] + " to redeem keys on your clipboard.", ToolTipIcon.Info); }, (detail, item) => { if (item == null) { Program.Context.icon.ShowBalloonTip(0, "Key redemption failed", "" + detail, ToolTipIcon.Error); } else { Program.Context.icon.ShowBalloonTip(0, "Key redemption successful", "You redeemed " + item, ToolTipIcon.Info); } }); NativeHot.Add(keybindings.bindings["Redeem Clipboard"].GetModifiers(), keybindings.bindings["Redeem Clipboard"].Key, () => { if (!steam.loggedOn) { icon.ShowBalloonTip(0, "Not logged on to Steam", "Log on to Steam before redeeming keys.", ToolTipIcon.Error); } else if (!Clipboard.ContainsText()) { icon.ShowBalloonTip(0, "Clipboard does not contain text", "Copy your key and try again.", ToolTipIcon.Error); } else { MatchCollection matches = new Regex("(\\w{5}\\-\\w{5}\\-\\w{5})").Matches(Clipboard.GetText()); if (matches.Count == 0) { icon.ShowBalloonTip(0, "Clipboard does not contain standard Steam keys", "Keydeem only supports standard 5-5-5 Steam keys. To force redemption, use " + keybindings.bindings["Force Redeem Clipboard"] + ".", ToolTipIcon.Error); } foreach (Match match in matches) { steam.RedeemKey(match.Value); } } }); // I don't know why this is necessary Thread.Sleep(100); NativeHot.Add(keybindings.bindings["Force Redeem Clipboard"].GetModifiers(), keybindings.bindings["Force Redeem Clipboard"].Key, () => { if (!steam.loggedOn) { icon.ShowBalloonTip(0, "Not logged on to Steam", "Log on to Steam before redeeming keys.", ToolTipIcon.Error); } else if (!Clipboard.ContainsText()) { icon.ShowBalloonTip(0, "Clipboard does not contain text", "Copy your key and try again.", ToolTipIcon.Error); } else { steam.RedeemKey(Clipboard.GetText()); } }); }
internal static void Set(Keybindings k) { File.WriteAllText("keybindings.json", JsonConvert.SerializeObject(k)); }