using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WebShortCutApp { public partial class MainForm : Form { private Dictionary shortcuts = new Dictionary() { { Keys.F1, "https://www.google.com" }, { Keys.F2, "https://www.github.com" }, { Keys.F3, "https://www.stackoverflow.com" }, { Keys.F4, "https://www.reddit.com" }, { Keys.F5, "https://www.crunchyroll.com" }, { Keys.F6, "https://www.twitter.com" }, { Keys.F7, "https://www.facebook.com" }, { Keys.F8, "https://www.instagram.com" }, { Keys.F9, "https://www.microsoft.com" }, { Keys.F10, "https://www.apple.com" }, { Keys.F11, "https://www.roblox.com" }, { Keys.F12, "https://www.netflix.com" } }; private int hotkeyId = 1; [DllImport("user32.dll")] private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk); [DllImport("user32.dll")] private static extern bool UnregisterHotKey(IntPtr hWnd, int id); public MainForm() { InitializeComponent(); RegisterAllHotkeys(); } private void RegisterAllHotkeys() { foreach (var kvp in shortcuts) { RegisterHotKey(this.Handle, hotkeyId++, 0x0000, (uint)kvp.Key); } } protected override void WndProc(ref Message m) { const int WM_HOTKEY = 0x0312; if (m.Msg == WM_HOTKEY) { int id = m.WParam.ToInt32(); Keys key = (Keys)(id - 1 + Keys.F1); if (shortcuts.TryGetValue(key, out string url)) { Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); } } base.WndProc(ref m); } protected override void Dispose(bool disposing) { if (disposing) { for (int i = 1; i < hotkeyId; i++) { UnregisterHotKey(this.Handle, i); } } base.Dispose(disposing); } } }