diff --git a/src/App.config b/src/App.config new file mode 100755 index 0000000..5754728 --- /dev/null +++ b/src/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Form1.Designer.cs b/src/Form1.Designer.cs new file mode 100755 index 0000000..ae107d5 --- /dev/null +++ b/src/Form1.Designer.cs @@ -0,0 +1,255 @@ +using System.Windows.Forms; + +namespace Program_Hide +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.btnRefresh = new System.Windows.Forms.Button(); + this.image = new System.Windows.Forms.PictureBox(); + this.lstWindows = new System.Windows.Forms.ComboBox(); + this.tm1 = new System.Windows.Forms.Timer(this.components); + this.button1 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.button2 = new System.Windows.Forms.Button(); + this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); + this.label2 = new System.Windows.Forms.Label(); + this.button3 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.fakePictureBox = new System.Windows.Forms.PictureBox(); + this.button6 = new System.Windows.Forms.Button(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + ((System.ComponentModel.ISupportInitialize)(this.image)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.fakePictureBox)).BeginInit(); + this.SuspendLayout(); + // + // btnRefresh + // + this.btnRefresh.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.btnRefresh.Location = new System.Drawing.Point(491, 153); + this.btnRefresh.Name = "btnRefresh"; + this.btnRefresh.Size = new System.Drawing.Size(75, 23); + this.btnRefresh.TabIndex = 7; + this.btnRefresh.Text = "Refresh"; + this.btnRefresh.UseVisualStyleBackColor = true; + this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click); + // + // image + // + this.image.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.image.BackColor = System.Drawing.SystemColors.ButtonFace; + this.image.Location = new System.Drawing.Point(221, 182); + this.image.Name = "image"; + this.image.Size = new System.Drawing.Size(345, 205); + this.image.TabIndex = 6; + this.image.TabStop = false; + // + // lstWindows + // + this.lstWindows.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.lstWindows.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.lstWindows.FormattingEnabled = true; + this.lstWindows.Location = new System.Drawing.Point(221, 155); + this.lstWindows.Name = "lstWindows"; + this.lstWindows.Size = new System.Drawing.Size(260, 21); + this.lstWindows.TabIndex = 5; + this.lstWindows.SelectedIndexChanged += new System.EventHandler(this.lstWindows_SelectedIndexChanged); + // + // tm1 + // + this.tm1.Tick += new System.EventHandler(this.tm1_Tick); + // + // button1 + // + this.button1.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.button1.Location = new System.Drawing.Point(572, 182); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(116, 44); + this.button1.TabIndex = 9; + this.button1.Text = "Create Keybind with Selected Window"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(129, 13); + this.label1.TabIndex = 10; + this.label1.Text = "Show/Hide This Window:"; + // + // textBox1 + // + this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.textBox1.Location = new System.Drawing.Point(1, 29); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(140, 33); + this.textBox1.TabIndex = 11; + this.textBox1.Click += new System.EventHandler(this.textBox1_Click); + this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); + this.textBox1.Enter += new System.EventHandler(this.textBox1_Enter); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(147, 29); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(108, 33); + this.button2.TabIndex = 12; + this.button2.Text = "Record Keys"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // notifyIcon1 + // + this.notifyIcon1.Text = "notifyIcon1"; + this.notifyIcon1.Visible = true; + // + // label2 + // + this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.label2.Location = new System.Drawing.Point(1, 65); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(140, 51); + this.label2.TabIndex = 13; + this.label2.Text = "Currently:"; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(147, 73); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(108, 34); + this.button3.TabIndex = 14; + this.button3.Text = "Reset to Default (Left Alt + Left Shift)"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(261, 34); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(75, 23); + this.button4.TabIndex = 15; + this.button4.Text = "Cancel"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(572, 232); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(116, 44); + this.button5.TabIndex = 16; + this.button5.Text = "Create Keybind with Application"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.button5_Click); + // + // fakePictureBox + // + this.fakePictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.fakePictureBox.BackColor = System.Drawing.SystemColors.ButtonFace; + this.fakePictureBox.Location = new System.Drawing.Point(221, 182); + this.fakePictureBox.Name = "fakePictureBox"; + this.fakePictureBox.Size = new System.Drawing.Size(345, 205); + this.fakePictureBox.TabIndex = 6; + this.fakePictureBox.TabStop = false; + // + // button6 + // + this.button6.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.button6.Location = new System.Drawing.Point(672, 12); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(116, 44); + this.button6.TabIndex = 17; + this.button6.Text = "View All Keybinds"; + this.button6.UseVisualStyleBackColor = true; + this.button6.Click += new System.EventHandler(this.button6_Click); + // + // timer1 + // + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.SystemColors.ControlLight; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button6); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.button3); + this.Controls.Add(this.label2); + this.Controls.Add(this.button2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Controls.Add(this.button1); + this.Controls.Add(this.btnRefresh); + this.Controls.Add(this.fakePictureBox); + this.Controls.Add(this.image); + this.Controls.Add(this.lstWindows); + this.Name = "Form1"; + this.Text = "Program Hide - Main Menu"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); + this.Load += new System.EventHandler(this.Form1_Load); + this.Resize += new System.EventHandler(this.Form1_Resize); + ((System.ComponentModel.ISupportInitialize)(this.image)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.fakePictureBox)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Button btnRefresh; + private System.Windows.Forms.PictureBox image; + private System.Windows.Forms.ComboBox lstWindows; + private System.Windows.Forms.Timer tm1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.NotifyIcon notifyIcon1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.PictureBox fakePictureBox; + private Button button6; + private Timer timer1; + } +} + diff --git a/src/Form1.cs b/src/Form1.cs new file mode 100755 index 0000000..c76f44b --- /dev/null +++ b/src/Form1.cs @@ -0,0 +1,828 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using KeyboardHook1; + +namespace Program_Hide +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + #region DWM Thumbnail Components + [DllImport("user32.dll", SetLastError = true)] + private static extern IntPtr GetWindow(IntPtr hWnd, int nIndex); + + [DllImport("dwmapi.dll")] + static extern int DwmRegisterThumbnail(IntPtr dest, IntPtr src, out IntPtr thumb); + + [DllImport("dwmapi.dll")] + static extern int DwmUnregisterThumbnail(IntPtr thumb); + + [DllImport("dwmapi.dll")] + static extern int DwmQueryThumbnailSourceSize(IntPtr thumb, out PSIZE size); + + [StructLayout(LayoutKind.Sequential)] + internal struct PSIZE + { + public int x; + public int y; + } + + [DllImport("dwmapi.dll")] + static extern int DwmUpdateThumbnailProperties(IntPtr hThumb, ref DWM_THUMBNAIL_PROPERTIES props); + + [DllImport("user32.dll")] + static extern int EnumWindows(EnumWindowsCallback lpEnumFunc, int lParam); + + delegate bool EnumWindowsCallback(IntPtr hwnd, int lParam); + + [DllImport("user32.dll")] + public static extern void GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); + + [DllImport("user32.dll")] + static extern ulong GetWindowLongA(IntPtr hWnd, int nIndex); + + static readonly int GWL_STYLE = -16; + + static readonly ulong WS_VISIBLE = 0x10000000L; + static readonly ulong WS_BORDER = 0x00800000L; + static readonly ulong TARGETWINDOW = WS_BORDER | WS_VISIBLE; + + internal class Window + { + public string Title; + public IntPtr Handle; + + public override string ToString() + { + return Title; + } + } + + [StructLayout(LayoutKind.Sequential)] + internal struct DWM_THUMBNAIL_PROPERTIES + { + public int dwFlags; + public Rect rcDestination; + public Rect rcSource; + public byte opacity; + public bool fVisible; + public bool fSourceClientAreaOnly; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct Rect + { + internal Rect(int left, int top, int right, int bottom) + { + Left = left; + Top = top; + Right = right; + Bottom = bottom; + } + + public int Left; + public int Top; + public int Right; + public int Bottom; + } + + private List windows; + + private void GetWindows() + { + windows = new List(); + + EnumWindows(Callback, 0); + + lstWindows.Items.Clear(); + foreach (Window w in windows) + { + lstWindows.Items.Add(w); + } + } + + private bool Callback(IntPtr hwnd, int lParam) + { + if (this.Handle != hwnd && (GetWindowLongA(hwnd, GWL_STYLE) & TARGETWINDOW) == TARGETWINDOW) + { + StringBuilder sb = new StringBuilder(200); + GetWindowText(hwnd, sb, sb.Capacity); + Window t = new Window(); + t.Handle = hwnd; + t.Title = sb.ToString(); + windows.Add(t); + } + + return true; //continue enumeration + } + + private IntPtr thumb; + + bool LoadedForm; + private void lstWindows_SelectedIndexChanged(object sender, EventArgs e) + { + StopRecording(); + if (!LoadedForm) + { + savedSize = image.Size; + LoadedForm = true; + } + + if (!image.Visible) + { + image.Visible = true; + } + + if (lstWindows.SelectedIndex > -1) + { + button1.Enabled = true; + + Window w = (Window)lstWindows.SelectedItem; + if (thumb != IntPtr.Zero) + DwmUnregisterThumbnail(thumb); + + int i = DwmRegisterThumbnail(this.Handle, w.Handle, out thumb); + if (i == 0) + UpdateThumb(); + + + tempHandle = w.Handle; + tempTitle = w.Title; + } + else + { + button1.Enabled = false; + } + } + + static readonly int DWM_TNP_VISIBLE = 0x8; + static readonly int DWM_TNP_OPACITY = 0x4; + static readonly int DWM_TNP_RECTDESTINATION = 0x1; + + + + const short HWND_BOTTOM = 1; + const short HWND_NOTOPMOST = -2; + const short HWND_TOP = 0; + const short HWND_TOPMOST = -1; + + const int SWP_NOMOVE = 0x0002; + const int SWP_NOSIZE = 0x0001; + const int SWP_SHOWWINDOW = 0x0040; + const int SWP_NOACTIVATE = 0x0010; + [DllImport("user32.dll", EntryPoint = "SetWindowPos")] + public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags); + + [DllImport("user32.dll")] + static extern bool SetForegroundWindow(IntPtr hWnd); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool IsWindow(IntPtr hWnd); + + [DllImport("User32.dll")] + static extern bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); //for all nCmdShow flags: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow + const int SW_MAXIMIZE = 3; + const int SW_SHOW = 5; + const int SW_SHOWNORMAL = 1; + const int SW_RESTORE = 9; //these also works with showwindowasync + + [DllImport("user32.dll", SetLastError = true)] + static extern bool BringWindowToTop(IntPtr hWnd); + + [DllImport("user32.dll")] + static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); + + //[DllImport("user32.dll", SetLastError = true)] + //static extern bool BringWindowToTop(HandleRef hWnd); + + #endregion + + + + + + #region Form1_Load | Intializes + + + KeyboardHook listener = new KeyboardHook(); + + IntPtr tempHandle; + string tempTitle; + + Color DarkGray = Color.FromArgb(41, 41, 41); + + public static List storedHandles = new List(); + public static List storedTitles = new List(); + + ContextMenuStrip contextMenu1 = new ContextMenuStrip(); + ToolStripMenuItem OpenItem = new ToolStripMenuItem("Open"); + ToolStripMenuItem HelpItem = new ToolStripMenuItem("Help"); + ToolStripMenuItem CloseItem = new ToolStripMenuItem("Close"); + + public static Form3 f3; + #endregion + + [STAThread] + private void Form1_Load(object sender, EventArgs e) + { + button6.Enabled = false; + f3 = new Form3(); + UpdateKeybindLabel(true); + + button4.Visible = false; + + notifyIcon1.Text = "Program Hide"; + notifyIcon1.ContextMenuStrip = contextMenu1; + notifyIcon1.Icon = SystemIcons.Information; + + notifyIcon1.Visible = true; + + contextMenu1.Items.Add(OpenItem); + contextMenu1.Items.Add(HelpItem); + contextMenu1.Items.Add(CloseItem); + + contextMenu1.BackColor = Color.Black; + + OpenItem.BackColor = DarkGray; + HelpItem.BackColor = DarkGray; + CloseItem.BackColor = DarkGray; + OpenItem.ForeColor = Color.White; + HelpItem.ForeColor = Color.White; + CloseItem.ForeColor = Color.White; + + OpenItem.Image = SystemIcons.Application.ToBitmap(); + HelpItem.Image = SystemIcons.Information.ToBitmap(); + CloseItem.Image = SystemIcons.Hand.ToBitmap(); + + OpenItem.Click += OpenItem_Click; + CloseItem.Click += CloseItem_Click; + HelpItem.Click += HelpItem_Click; + + notifyIcon1.ShowBalloonTip(3000, "Program Hide - Startup Notification", "Right Click the Tool Tip or Click Here for Help Using this Product.", ToolTipIcon.Info); + notifyIcon1.BalloonTipClicked += (send, args) => + { + ShowHelp(); + }; + + listener.KeyDown += listener_KeyDown; + listener.KeyUp += listener_KeyUp; + + button1.Enabled = false; + + GetWindows(); + + tm1.Enabled = true; + timer1.Enabled = true; + tm1.Interval = 1000; + } + + private void OpenItem_Click(object sender, EventArgs e) + { + this.Show(); + BringWindowToTop(this.Handle); + } + + private void HelpItem_Click(object sender, EventArgs e) + { + ShowHelp(); + } + + private void CloseItem_Click(object sender, EventArgs e) + { + this.Close(); + } + + public void ShowHelp() + { + MessageBox.Show("Not Implemented Yet!", "Program Hide", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + + #region KeyDown Detecion System + + bool alreadyShownMB; + bool keyIsNew; + + List currentKeys = new List(); + private void listener_KeyDown(KeyboardHook.VKeys key) + { + if (!currentKeys.Contains(key)) + { + currentKeys.Add(key); + keyIsNew = true; + } + + if (keyIsNew) + { + if (ShowHideRecording) + { + if (!TempKeysList.Contains(key)) + { + TempKeysList.Add(key); + + if (!alreadyShownMB) + { + if (TempKeysList.Count > 4) + { + alreadyShownMB = true; + MessageBox.Show("Reminder: The current key combination max is 4.", "Program Hide - Reminder", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + textBox1.Text = ""; + + for (int i = 0; i < TempKeysList.Count; i++) + { + if (i < 1) + { + textBox1.Text += TempKeysList[i].ToString(); + } + else + { + textBox1.Text += " + " + TempKeysList[i].ToString(); + } + + textBox1.SelectionStart = textBox1.TextLength; + } + } + } + + keyIsNew = false; + } + #endregion + + #region KeyUp Detection System + + private void listener_KeyUp(KeyboardHook.VKeys key) + { + if (currentKeys.Contains(key)) + { + currentKeys.Remove(key); + } + + if (ShowHideRecording) + { + if (TempKeysList.Contains(key)) + { + TempKeysList.Remove(key); + + textBox1.Text = ""; + + for (int i = 0; i < TempKeysList.Count; i++) + { + if (i < 1) + { + textBox1.Text += TempKeysList[i].ToString(); + } + else + { + textBox1.Text += " + " + TempKeysList[i].ToString(); + } + + textBox1.SelectionStart = textBox1.TextLength; + } + } + } + } + #endregion + + + bool keyListenerInstalled; + public void UpdateKeyRecording(bool boolean) + { + if (boolean) + { + keyListenerInstalled = true; + listener.Install(); + } + else + { + keyListenerInstalled = false; + listener.Uninstall(); + } + } + + + public static bool ShowHideRecording; + public static bool Form1ForceRecord; + + public static List ShowHideKeysList = new List(); + List TempKeysList = new List(); + private void button2_Click(object sender, EventArgs e) + { + Form1ForceRecord = true; + Form2.Form2ForceRecord = false; + + this.ActiveControl = null; + if (!ShowHideRecording) + { + timer1.Enabled = true; + UpdateKeyRecording(true); + TempKeysList.Clear(); + + ShowHideRecording = true; + button2.Text = "Stop Recording"; + button4.Visible = true; + } + else + { + timer1.Enabled = false; + UpdateKeyRecording(false); + alreadyShownMB = false; + ShowHideRecording = false; + button2.Text = "Record Keys"; + button4.Visible = false; + textBox1.Text = ""; + + if (TempKeysList.Count > 4 || TempKeysList.Count < 2) + { + if (TempKeysList.Count > 4) + { + MessageBox.Show("Your new key combination was not saved.\nReason: The key combination contains more than 4 keys.", "Program Hide - Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else if (TempKeysList.Count < 2 && TempKeysList.Count > 0) + { + MessageBox.Show("Your new key combination was not saved.\nReason: The key combination contains less than 2 keys.", "Program Hide - Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else if (TempKeysList.Count == 0) + { + MessageBox.Show("Your new key combination was not saved.\nReason: The key combination is empty.", "Program Hide - Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + else + { + SetNewKeys(); + UpdateKeybindLabel(false); + + if (addedYet) + { + Form3.AllKeyBinds[0] = ShowHideKeysList; + } + } + + currentKeys.Clear(); + } + } + + public void SetNewKeys() + { + ShowHideKeysList = TempKeysList.ToList(); + } + + public void UpdateKeybindLabel(bool resetDefault) + { + if (resetDefault) + { + ShowHideKeysList.Clear(); + ShowHideKeysList.Add(KeyboardHook.VKeys.LMENU); + ShowHideKeysList.Add(KeyboardHook.VKeys.LSHIFT); + } + + label2.Text = ""; + label2.Text += "Current:\n"; + for (int i = 0; i < ShowHideKeysList.Count; i++) + { + if (i < 1) + { + label2.Text += ShowHideKeysList[i].ToString(); + } + else + { + label2.Text += " + " + ShowHideKeysList[i].ToString(); + } + } + } + + private void button3_Click(object sender, EventArgs e) + { + StopRecording(); + if (ShowHideKeysList.Count == 2) + { + if (ShowHideKeysList.Contains(KeyboardHook.VKeys.LMENU) && ShowHideKeysList.Contains(KeyboardHook.VKeys.LSHIFT)) + { + return; + } + } + UpdateKeybindLabel(true); + } + + private void button4_Click(object sender, EventArgs e) + { + StopRecording(); + } + + public void StopRecording() + { + Form2.Form2ForceRecord = false; + if (button4.Visible) + { + button4.Visible = false; + } + + ShowHideRecording = false; + button2.Text = "Record Keys"; + listener.Uninstall(); + button4.Visible = false; + textBox1.Text = ""; + } + + + private void tm1_Tick(object sender, EventArgs e) + { + for (int i = 0; i < windows.Count; i++) + { + if (!IsWindow(windows[i].Handle)) + { + lstWindows.Items.RemoveAt(i); + windows.RemoveAt(i); + lstWindows.SelectedIndex = -1; + button1.Enabled = false; + } + } + UpdateThumb(); + } + + public static Form2 f2; + private void button1_Click(object sender, EventArgs e) + { + StopRecording(); + if (ShowHideKeysList.Count == 2 && ShowHideKeysList.Contains(KeyboardHook.VKeys.LSHIFT) && ShowHideKeysList.Contains(KeyboardHook.VKeys.LMENU)) + { + DialogResult returnValue = MessageBox.Show("Are you sure you want to keep the Default Keybind?\nIt can be changed later in the Keybind List Menu", "Program Hide - Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + + if (!(returnValue == DialogResult.Yes)) + { + return; + } + } + + AddToFullList(); + + EnableButtonSix(); + + if (!IsWindow(tempHandle)) + { + MessageBox.Show("The window: \n\"" + tempTitle + "\"\n no longer exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + if (lstWindows.SelectedIndex > -1) + { + lstWindows.Items.RemoveAt(lstWindows.SelectedIndex); + } + lstWindows.SelectedIndex = -1; + return; + } + + OpenOfType("WIN"); + } + + private void button5_Click(object sender, EventArgs e) + { + StopRecording(); + if (ShowHideKeysList.Count == 2 && ShowHideKeysList.Contains(KeyboardHook.VKeys.LSHIFT) && ShowHideKeysList.Contains(KeyboardHook.VKeys.LMENU)) + { + DialogResult returnValue = MessageBox.Show("Are you sure you want to keep the Default Keybind?\nIt can be changed later in the Keybind List Menu", "Program Hide - Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + + if (!(returnValue == DialogResult.Yes)) + { + return; + } + } + + AddToFullList(); + EnableButtonSix(); + + + OpenOfType("APP"); + } + + public void OpenOfType(string type) + { + fc = Application.OpenForms; + for (int i = 0; i < fc.Count; i++) + { + if (fc[i].Name == "Form2") + { + if (f2.Tag.ToString() == type) + { + f2.Show(); + f2.BringToFront(); + break; + } + } + if (i == fc.Count - 1) + { + if (type == "WIN") + { + f2 = new Form2(tempHandle, tempTitle, type); + } + else + { + f2 = new Form2((IntPtr)0, null, type); + } + f2.Show(); + f2.BringToFront(); + } + } + } + + public void EnableButtonSix() + { + if (Form3.AllKeyBinds.Count > 0) + { + button6.Enabled = true; + button6_Click(new object(), new EventArgs()); + f3.Show(); + f3.Hide(); + } + } + + + private void button6_Click(object sender, EventArgs e) + { + StopRecording(); + OpenFormThree(); + } + + FormCollection fc; + public void OpenFormThree() + { + fc = Application.OpenForms; + for (int i = 0; i < fc.Count; i++) + { + if (fc[i].Name == "Form3") + { + break; + } + + if (i == fc.Count - 1) + { + f3 = new Form3(); + } + } + f3.Show(); + f3.BringToFront(); + } + + bool addedYet; + public void AddToFullList() + { + if (!addedYet) + { + Form3.AllKeyBinds.Add(ShowHideKeysList.ToList()); + Form3.AllHandles.Add(this.Handle); + Form3.AllTitles.Add(this.Text); + Form3.ShowingWindow.Add(true); + Form3.Maximize.Add(false); + addedYet = true; + } + } + + private void UpdateThumb() + { + if (thumb != IntPtr.Zero) + { + PSIZE size; + DwmQueryThumbnailSourceSize(thumb, out size); + + DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES(); + props.dwFlags = DWM_TNP_VISIBLE | DWM_TNP_RECTDESTINATION | DWM_TNP_OPACITY; + + props.fVisible = true; + props.opacity = 255; + + + if (size.x < image.Width && size.y < image.Height) + { + props.rcDestination = new Rect(image.Left + ((image.Width - (props.rcDestination.Left + size.x)) / 2), image.Top + ((image.Height - (props.rcDestination.Top + size.y)) / 2), image.Right, image.Bottom); + } + else if (size.x < image.Width && !(size.y < image.Height)) + { + props.rcDestination = new Rect(image.Left + ((image.Width - (props.rcDestination.Left + size.x)) / 2), image.Top, image.Right, image.Bottom); + } + else if (!(size.x < image.Width) && size.y < image.Height) + { + props.rcDestination = new Rect(image.Left, image.Top + ((image.Height - (props.rcDestination.Top + size.y)) / 2), image.Right, image.Bottom); + } + else if (!(size.x < image.Width && size.y < image.Height)) + { + props.rcDestination = new Rect(image.Left, image.Top, image.Right, image.Bottom); + } + + if (size.x < image.Width) + props.rcDestination.Right = props.rcDestination.Left + size.x; + if (size.y < image.Height) + props.rcDestination.Bottom = props.rcDestination.Top + size.y; + + DwmUpdateThumbnailProperties(thumb, ref props); + } + } + + private void Form1_Resize(object sender, EventArgs e) + { + UpdateThumb(); + } + + + List PreviousHandles = new List(); + List PreviousTitles = new List(); + int previousIndex; + Size savedSize; + private void btnRefresh_Click(object sender, EventArgs e) + { + StopRecording(); + PreviousHandles.Clear(); + PreviousTitles.Clear(); + + foreach (Window w in windows) + { + PreviousHandles.Add(w.Handle); + PreviousTitles.Add(w.Title); + } + previousIndex = lstWindows.SelectedIndex; + + GetWindows(); + + if (previousIndex > -1) + { + if (windows[previousIndex].Handle == PreviousHandles[previousIndex]) + { + lstWindows.SelectedIndex = previousIndex; + } + else + { + savedSize = image.Size; + image.Size = new Size(0, 0); + } + } + } + + private void Form1_FormClosing(object sender, FormClosingEventArgs e) + { + if (MessageBox.Show("Are you sure you would like to close the program?\nNote: Your keybinds will no longer be functional.", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + notifyIcon1.BalloonTipClosed += (s, args) => + { + var thisIcon = (NotifyIcon)sender; + thisIcon.Visible = false; + thisIcon.Dispose(); + }; + + if (keyListenerInstalled) + { + listener.Uninstall(); + } + + listener.KeyDown -= listener_KeyDown; + listener.KeyUp -= listener_KeyUp; + } + else + { + e.Cancel = true; + } + } + + private void textBox1_Click(object sender, EventArgs e) + { + this.ActiveControl = null; + } + + private void textBox1_Enter(object sender, EventArgs e) + { + this.ActiveControl = null; + } + + private void textBox1_TextChanged(object sender, EventArgs e) + { + this.ActiveControl = null; + } + + private void timer1_Tick(object sender, EventArgs e) + { + if (ShowHideRecording) + { + if (Form2.Form2ForceRecord) + { + StopRecording(); + } + } + } + } +} \ No newline at end of file diff --git a/src/Form1.resx b/src/Form1.resx new file mode 100755 index 0000000..a96cc78 --- /dev/null +++ b/src/Form1.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 90, 17 + + + 203, 17 + + \ No newline at end of file diff --git a/src/Form2.Designer.cs b/src/Form2.Designer.cs new file mode 100755 index 0000000..a23f9dd --- /dev/null +++ b/src/Form2.Designer.cs @@ -0,0 +1,216 @@ +namespace Program_Hide +{ + partial class Form2 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.label1 = new System.Windows.Forms.Label(); + this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.button4 = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.button2 = new System.Windows.Forms.Button(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.checkBox2 = new System.Windows.Forms.CheckBox(); + this.checkBox3 = new System.Windows.Forms.CheckBox(); + this.button1 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(359, 32); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(60, 24); + this.label1.TabIndex = 0; + this.label1.Text = "label1"; + // + // checkBox1 + // + this.checkBox1.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.checkBox1.AutoSize = true; + this.checkBox1.Location = new System.Drawing.Point(334, 63); + this.checkBox1.Name = "checkBox1"; + this.checkBox1.Size = new System.Drawing.Size(69, 17); + this.checkBox1.TabIndex = 9; + this.checkBox1.TabStop = false; + this.checkBox1.Text = "Maximize"; + this.checkBox1.UseVisualStyleBackColor = true; + this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(173, 134); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(75, 23); + this.button4.TabIndex = 20; + this.button4.TabStop = false; + this.button4.Text = "Cancel"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // label2 + // + this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.label2.Location = new System.Drawing.Point(12, 122); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(140, 51); + this.label2.TabIndex = 18; + this.label2.Text = "Currently:"; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(158, 86); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(108, 33); + this.button2.TabIndex = 17; + this.button2.TabStop = false; + this.button2.Text = "Record Keys"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // textBox1 + // + this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.textBox1.Location = new System.Drawing.Point(12, 86); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(140, 33); + this.textBox1.TabIndex = 16; + this.textBox1.TabStop = false; + this.textBox1.Click += new System.EventHandler(this.textBox1_Click); + this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); + this.textBox1.Enter += new System.EventHandler(this.textBox1_Enter); + // + // checkBox2 + // + this.checkBox2.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.checkBox2.AutoSize = true; + this.checkBox2.Location = new System.Drawing.Point(334, 86); + this.checkBox2.Name = "checkBox2"; + this.checkBox2.Size = new System.Drawing.Size(130, 17); + this.checkBox2.TabIndex = 21; + this.checkBox2.TabStop = false; + this.checkBox2.Text = "Create Instance Once"; + this.checkBox2.UseVisualStyleBackColor = true; + this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); + // + // checkBox3 + // + this.checkBox3.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.checkBox3.AutoSize = true; + this.checkBox3.Location = new System.Drawing.Point(334, 109); + this.checkBox3.Name = "checkBox3"; + this.checkBox3.Size = new System.Drawing.Size(137, 17); + this.checkBox3.TabIndex = 22; + this.checkBox3.TabStop = false; + this.checkBox3.Text = "Create Instance Always"; + this.checkBox3.UseVisualStyleBackColor = true; + this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(343, 134); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(112, 26); + this.button1.TabIndex = 23; + this.button1.TabStop = false; + this.button1.Text = "Save to Keybind List"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(596, 32); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(98, 33); + this.button3.TabIndex = 24; + this.button3.TabStop = false; + this.button3.Text = "Type in Manually"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(700, 32); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(88, 33); + this.button5.TabIndex = 24; + this.button5.TabStop = false; + this.button5.Text = "Use File Dialog"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.button5_Click); + // + // timer1 + // + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // Form2 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button5); + this.Controls.Add(this.button3); + this.Controls.Add(this.button1); + this.Controls.Add(this.checkBox3); + this.Controls.Add(this.checkBox2); + this.Controls.Add(this.button4); + this.Controls.Add(this.label2); + this.Controls.Add(this.button2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.checkBox1); + this.Controls.Add(this.label1); + this.Name = "Form2"; + this.Text = "Program Hide - Create"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form2_FormClosing); + this.Load += new System.EventHandler(this.Form2_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.CheckBox checkBox1; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.CheckBox checkBox2; + private System.Windows.Forms.CheckBox checkBox3; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Timer timer1; + } +} \ No newline at end of file diff --git a/src/Form2.cs b/src/Form2.cs new file mode 100755 index 0000000..d568553 --- /dev/null +++ b/src/Form2.cs @@ -0,0 +1,511 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Microsoft.VisualBasic; +using KeyboardHook1; +using System.Diagnostics; +using System.Threading; + +namespace Program_Hide +{ + public partial class Form2 : Form + { + public IntPtr inHandle; + public string inTitle; + public string keybindMethod; + + public Form2(IntPtr inputHandle, string inputTitle, string theKeybindMethod) //prevent making duplicate of the same window + { + InitializeComponent(); + + this.Tag = theKeybindMethod; + + if (theKeybindMethod == "WIN") + { + inHandle = inputHandle; + inTitle = inputTitle; + checkBox1.Visible = true; + checkBox2.Visible = false; + checkBox3.Visible = false; + button1.Location = new Point(342, 91); + } + + if (theKeybindMethod == "APP") + { + checkBox1.Visible = true; + checkBox2.Visible = true; + checkBox3.Visible = true; + button1.Location = new Point(342, 136); + } + + keybindMethod = theKeybindMethod; + } + + #region Form2_Load | Intializes + + KeyboardHook listener = new KeyboardHook(); + + OpenFileDialog ofd1 = new OpenFileDialog(); + + ToolTip tt1 = new ToolTip(); + ToolTip tt2 = new ToolTip(); + ToolTip tt3 = new ToolTip(); + #endregion + + + + private void Form2_Load(object sender, EventArgs e) + { + timer1.Enabled = true; + button4.Visible = false; + button1.Enabled = false; + listener.KeyDown += listener_KeyDown; + listener.KeyUp += listener_KeyUp; + + #region CheckBox | Tooltips + + tt1.AutoPopDelay = 32767; + tt1.InitialDelay = 500; + tt1.ReshowDelay = 500; + tt1.SetToolTip(checkBox1, "On Keybind Press: Maximize when the Window is Shown"); + + tt2.AutoPopDelay = 32767; + tt2.InitialDelay = 500; + tt2.ReshowDelay = 500; + tt2.SetToolTip(checkBox2, "On Keybind Press: Create Instance of App if not Running"); + + tt3.AutoPopDelay = 32767; + tt3.InitialDelay = 500; + tt3.ReshowDelay = 500; + tt3.SetToolTip(checkBox3, "On Keybind Press: Always create new Instance of App"); + #endregion + + if (keybindMethod == "WIN") + { + if (inTitle.Length <= 28) + { + label1.Text = "\"" + inTitle + "\""; + } + else + { + label1.Text = "\"" + inTitle.Substring(0, 28) + "...\""; + } + + label1.Location = new Point(((this.Width / 2) - label1.Width / 2), label1.Location.Y); + } + + if (keybindMethod == "APP") + { + label1.Visible = false; + checkBox2.Visible = true; + checkBox3.Visible = true; + } + } + + #region KeyUp Detection System + bool alreadyShownMB; + bool keyIsNew; + public static bool NewWindowRecording; + public static bool Form2ForceRecord; + + public static List NewWindowKeysList = new List(); + + List currentKeys = new List(); + List TempKeysList = new List(); + private void listener_KeyDown(KeyboardHook.VKeys key) + { + if (!currentKeys.Contains(key)) + { + currentKeys.Add(key); + keyIsNew = true; + } + + if (keyIsNew) + { + if (NewWindowRecording) + { + if (!TempKeysList.Contains(key)) + { + TempKeysList.Add(key); + + if (!alreadyShownMB) + { + if (TempKeysList.Count > 4) + { + alreadyShownMB = true; + MessageBox.Show("Reminder: The current key combination max is 4.", "Program Hide - Reminder", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + textBox1.Text = ""; + + for (int i = 0; i < TempKeysList.Count; i++) + { + if (i < 1) + { + textBox1.Text += TempKeysList[i].ToString(); + } + else + { + textBox1.Text += " + " + TempKeysList[i].ToString(); + } + + textBox1.SelectionStart = textBox1.TextLength; + } + } + } + keyIsNew = false; + } + #endregion + + public void listener_KeyUp(KeyboardHook.VKeys key) + { + if (currentKeys.Contains(key)) + { + currentKeys.Remove(key); + } + + if (NewWindowRecording) + { + if (TempKeysList.Contains(key)) + { + TempKeysList.Remove(key); + + textBox1.Text = ""; + + for (int i = 0; i < TempKeysList.Count; i++) + { + if (i < 1) + { + textBox1.Text += TempKeysList[i].ToString(); + } + else + { + textBox1.Text += " + " + TempKeysList[i].ToString(); + } + + textBox1.SelectionStart = textBox1.TextLength; + } + } + } + } + + string tempFileLocation; + string applicationLocation; + string fileName; + private void button3_Click(object sender, EventArgs e) + { + StopRecording(); + tempFileLocation = Interaction.InputBox("Please Enter your Application's File Path", "Open File"); + + if (tempFileLocation.Contains(".exe") && File.Exists(tempFileLocation)) + { + applicationLocation = ofd1.FileName; + fileName = Path.GetFileName(tempFileLocation); + ReceivedFile(); + } + } + + private void button5_Click(object sender, EventArgs e) + { + StopRecording(); + ofd1.Filter = "Executable Files (*.exe)|*.exe"; + ofd1.InitialDirectory = Environment.ExpandEnvironmentVariables("%PROGRAMFILES(x86)%"); + ofd1.Title = "Select your Application File"; + ofd1.CheckFileExists = true; + ofd1.CheckPathExists = true; + ofd1.Multiselect = false; + + if (ofd1.ShowDialog() != DialogResult.OK) + { + return; + } + else + { + applicationLocation = ofd1.FileName; + fileName = Path.GetFileName(ofd1.FileName); + ReceivedFile(); + } + } + + public void ReceivedFile() + { + if (fileName.Length <= 28) + { + label1.Text = "\"" + fileName + "\""; + } + else + { + label1.Text = "\"" + fileName.Substring(0, 28) + "....exe\""; + } + + label1.Location = new Point(((this.Width / 2) - label1.Width / 2), label1.Location.Y); + label1.Visible = true; + } + + private void checkBox2_CheckedChanged(object sender, EventArgs e) + { + StopRecording(); + + if (checkBox2.Checked && checkBox3.Checked) + { + checkBox3.Checked = false; + } + } + + private void checkBox3_CheckedChanged(object sender, EventArgs e) + { + StopRecording(); + + if (checkBox2.Checked && checkBox3.Checked) + { + checkBox2.Checked = false; + } + } + + string RepeatedKeybinds; + DialogResult AddKeybindResult; + private void button1_Click(object sender, EventArgs e) + { + StopRecording(); + RepeatedKeybinds = ""; + for (int i1 = 0; i1 < Form3.AllKeyBinds.Count; i1++) + { + for (int i2 = 0; i2 < NewWindowKeysList.Count; i2++) + { + if (!Form3.AllKeyBinds[i1].Contains(NewWindowKeysList[i2])) + { + break; + } + else + { + if (i2 == NewWindowKeysList.Count - 1) + { + RepeatedKeybinds += "\n\"" + Form3.AllTitles[i1] + "\""; + Debug.WriteLine("TRUE"); + break; + } + } + } + } + + if (!(RepeatedKeybinds == "")) + { + AddKeybindResult = MessageBox.Show("Your current keybind contains keys that can open other keybinds!\nYou can continue if you would like, but it is not recommended.\nWould you like to continue?\n\nEffected Keybinds:" + RepeatedKeybinds, + "Program Hide - Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + } + + if (AddKeybindResult == DialogResult.No) + { + return; + } + + + if (keybindMethod == "WIN") + { + Form3.Maximize.Add(checkBox1.Checked); + Form3.AllHandles.Add(inHandle); + Form3.AllTitles.Add(inTitle); + + Form3.ProgramType.Add("WIN"); + } + + if (keybindMethod == "APP") + { + Form3.Maximize.Add(checkBox1.Checked); + Form3.CIOnce.Add(checkBox2.Checked); + Form3.CIAlways.Add(checkBox3.Checked); + Form3.AllTitles.Add(fileName); + + Form3.ProgramType.Add("APP"); + } + + Form3.ShowingWindow.Add(false); + Form3.AllKeyBinds.Add(NewWindowKeysList); + + MessageBox.Show("Successfully added keybind!", "Program Hide - Success", MessageBoxButtons.OK, MessageBoxIcon.Information); + OpenFormThree(); + this.Close(); + } + + FormCollection fc; + public void OpenFormThree() + { + fc = Application.OpenForms; + for (int i = 0; i < fc.Count; i++) + { + if (fc[i].Name == "Form3") + { + break; + } + + if (i == fc.Count - 1) + { + Form1.f3 = new Form3(); + } + } + + Form1.f3.Show(); + Form1.f3.BringToFront(); + } + + bool keyListenerInstalled; + public void UpdateKeyRecording(bool boolean) + { + if (boolean) + { + keyListenerInstalled = true; + listener.Install(); + } + else + { + keyListenerInstalled = false; + listener.Uninstall(); + } + } + + private void button2_Click(object sender, EventArgs e) + { + Form2ForceRecord = true; + Form1.Form1ForceRecord = false; + + + this.ActiveControl = null; + if (!NewWindowRecording) + { + timer1.Enabled = true; + UpdateKeyRecording(true); + TempKeysList.Clear(); + NewWindowRecording = true; + button2.Text = "Stop Recording"; + button4.Visible = true; + } + else + { + timer1.Enabled = false; + UpdateKeyRecording(false); + alreadyShownMB = false; + NewWindowRecording = false; + button2.Text = "Record Keys"; + button4.Visible = false; + textBox1.Text = ""; + + if (TempKeysList.Count > 4 || TempKeysList.Count < 2) + { + if (TempKeysList.Count > 4) + { + MessageBox.Show("Your new key combination was not saved.\nReason: The key combination contains more than 4 keys.", "Program Hide - Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else if (TempKeysList.Count < 2 && TempKeysList.Count > 0) + { + MessageBox.Show("Your new key combination was not saved.\nReason: The key combination contains less than 2 keys.", "Program Hide - Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else if (TempKeysList.Count == 0) + { + MessageBox.Show("Your new key combination was not saved.\nReason: The key combination is empty.", "Program Hide - Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + else + { + SetNewKeys(); + UpdateKeybindLabel(); + } + + currentKeys.Clear(); + } + } + + public void SetNewKeys() + { + NewWindowKeysList = TempKeysList.ToList(); + button1.Enabled = true; + } + + public void UpdateKeybindLabel() + { + + label2.Text = ""; + label2.Text += "Current:\n"; + for (int i = 0; i < NewWindowKeysList.Count; i++) + { + if (i < 1) + { + label2.Text += NewWindowKeysList[i].ToString(); + } + else + { + label2.Text += " + " + NewWindowKeysList[i].ToString(); + } + } + } + + private void Form2_FormClosing(object sender, FormClosingEventArgs e) + { + if (keyListenerInstalled) + { + listener.Uninstall(); + } + + listener.KeyDown -= listener_KeyDown; + listener.KeyUp -= listener_KeyUp; + } + + private void button4_Click(object sender, EventArgs e) + { + StopRecording(); + } + + public void StopRecording() + { + Form1.Form1ForceRecord = false; + if (button4.Visible) + { + button4.Visible = false; + } + + NewWindowRecording = false; + button2.Text = "Record Keys"; + listener.Uninstall(); + button4.Visible = false; + textBox1.Text = ""; + } + + private void textBox1_Click(object sender, EventArgs e) + { + this.ActiveControl = null; + } + + private void textBox1_Enter(object sender, EventArgs e) + { + this.ActiveControl = null; + } + + private void textBox1_TextChanged(object sender, EventArgs e) + { + this.ActiveControl = null; + } + + private void timer1_Tick(object sender, EventArgs e) + { + if (NewWindowRecording) + { + if (Form1.Form1ForceRecord) + { + StopRecording(); + } + } + } + + private void checkBox1_CheckedChanged(object sender, EventArgs e) + { + StopRecording(); + } + } +} diff --git a/src/Form2.resx b/src/Form2.resx new file mode 100755 index 0000000..aac33d5 --- /dev/null +++ b/src/Form2.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/src/Form3.Designer.cs b/src/Form3.Designer.cs new file mode 100755 index 0000000..f246281 --- /dev/null +++ b/src/Form3.Designer.cs @@ -0,0 +1,91 @@ +namespace Program_Hide +{ + partial class Form3 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.panel1 = new System.Windows.Forms.Panel(); + this.label1 = new System.Windows.Forms.Label(); + this.panel1.SuspendLayout(); + this.SuspendLayout(); + // + // timer1 + // + this.timer1.Interval = 1000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.BackColor = System.Drawing.SystemColors.ControlDark; + this.panel1.Controls.Add(this.label1); + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(800, 450); + this.panel1.TabIndex = 0; + // + // label1 + // + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(685, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(71, 24); + this.label1.TabIndex = 0; + this.label1.Text = "Total: 0"; + // + // Form3 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.panel1); + this.Name = "Form3"; + this.Text = "Form3"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form3_FormClosing); + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form3_FormClosed); + this.Load += new System.EventHandler(this.Form3_Load); + this.VisibleChanged += new System.EventHandler(this.Form3_VisibleChanged); + this.Resize += new System.EventHandler(this.Form3_Resize); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Label label1; + } +} \ No newline at end of file diff --git a/src/Form3.cs b/src/Form3.cs new file mode 100755 index 0000000..1144d06 --- /dev/null +++ b/src/Form3.cs @@ -0,0 +1,381 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using KeyboardHook1; + +namespace Program_Hide +{ + public partial class Form3 : Form + { + public Form3() + { + InitializeComponent(); + } + + [DllImport("user32.dll")] + static extern bool SetForegroundWindow(IntPtr hWnd); + + [DllImport("user32.dll")] + static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); + const int SW_MAXIMIZE = 3; + const int SW_SHOW = 5; + const int SW_HIDE = 0; + const int SW_SHOWNORMAL = 1; + const int SW_RESTORE = 9; + + public static List> AllKeyBinds = new List>(); //list of keyvalues inside of a list of keybinds + public static List AllHandles = new List(); + public static List AllTitles = new List(); + + public static List Maximize = new List(); + public static List CIOnce = new List(); + public static List CIAlways = new List(); + + public static List ProgramType = new List(); + + public static List ShowingWindow = new List(); + + ScrollBar vScrollBar1; + + public KeyboardHook listener = new KeyboardHook(); + private void Form3_Load(object sender, EventArgs e) + { + label1.Visible = false; + panel1.Location = new Point(0, 0); + panel1.MouseWheel += Panel1_MouseWheel; + + vScrollBar1 = new VScrollBar(); + vScrollBar1.Dock = DockStyle.Right; + + vScrollBar1.Scroll += (osender, eargs) => { + UpdateScroll(true); + }; + + vScrollBar1.Maximum = 0; + + + Debug.WriteLine(vScrollBar1.Maximum); + + this.Controls.Add(vScrollBar1); + vScrollBar1.BringToFront(); + + timer1.Enabled = true; + + listener.KeyDown += Listener_KeyDown; + listener.KeyUp += Listener_KeyUp; + + listener.Install(); + } + + + public void ShowForm(int i) + { + if (i == 0) + { + if (Form1.ShowHideRecording) + { + return; + } + } + if (ShowingWindow[i]) + { + ShowWindowAsync(AllHandles[i], SW_HIDE); + ShowingWindow[i] = false; + } + else + { + ShowWindowAsync(AllHandles[i], SW_SHOW); + SetForegroundWindow(AllHandles[i]); + + if (Maximize[i]) + { + ShowWindowAsync(AllHandles[i], SW_MAXIMIZE); + } + ShowingWindow[i] = true; + } + } + + + List CurrentKeys = new List(); + private void Listener_KeyDown(KeyboardHook.VKeys key) + { + if (!CurrentKeys.Contains(key)) + { + CurrentKeys.Add(key); + + + if (CurrentKeys.Count >= 2) + { + for (int i = 0; i < AllKeyBinds.Count; i++) + { + for (int a = 0; a < AllKeyBinds[i].Count; a++) + { + if (!CurrentKeys.Contains(AllKeyBinds[i][a])) + { + break; + } + else if (a == AllKeyBinds[i].Count - 1) + { + ShowForm(i); + UpdatePanels(); + } + } + } + } + + + + + + } + } + private void Listener_KeyUp(KeyboardHook.VKeys key) + { + CurrentKeys.Remove(key); + } + + int changeInScroll = 5; + int scrollFreeSpace; + float VScrollBar1Translation; + private void Panel1_MouseWheel(object sender, MouseEventArgs e) + { + SendScrollInput(e); + } + + bool resetPanelLocation; + public void SendScrollInput(MouseEventArgs e) + { + Debug.WriteLine(vScrollBar1.Value + " / " + vScrollBar1.Maximum); + + if (panel1.Height - this.ClientSize.Height > 0) + { + scrollFreeSpace = panel1.Height - this.ClientSize.Height; + Debug.WriteLine(scrollFreeSpace); + + VScrollBar1Translation = (float)Math.Floor((double)(scrollFreeSpace / changeInScroll)); + vScrollBar1.Maximum = (int)VScrollBar1Translation; + Debug.WriteLine("OUT OF: " + scrollFreeSpace / changeInScroll); + Debug.WriteLine(vScrollBar1.Maximum); + + if (vScrollBar1.Maximum > 0) + { + if (e.Delta > 0) + { + if (vScrollBar1.Value - changeInScroll > vScrollBar1.Minimum) + { + vScrollBar1.Value -= 5; + } + else + { + vScrollBar1.Value = 0; + } + } + else + { + if (vScrollBar1.Value + changeInScroll < vScrollBar1.Maximum) + { + vScrollBar1.Value += 5; + } + else + { + Debug.WriteLine(vScrollBar1.Maximum); + vScrollBar1.Value = vScrollBar1.Maximum; + } + } + + UpdateScroll(false); + } + } + } + + + int tempInt1; + public void UpdateScroll(bool usedScrollBar) + { + if (resetPanelLocation) + { + resetPanelLocation = false; + panel1.Location = new Point(0, 0); + vScrollBar1.Value = 0; + } + else + { + tempInt1 = (0 - (vScrollBar1.Value * (panel1.Height / vScrollBar1.Maximum)) + (vScrollBar1.Value * ((this.ClientSize.Height + 40) / vScrollBar1.Maximum))); + if (usedScrollBar) + { + Debug.WriteLine(vScrollBar1.Value + " OUT OF " + vScrollBar1.Maximum); + + if (vScrollBar1.Value > ((vScrollBar1.Maximum / 10) * 9)) + { + Debug.WriteLine("true"); + panel1.Location = new Point(0, tempInt1); + } + else + { + Debug.WriteLine("TRUE"); + panel1.Location = new Point(0, tempInt1 - (int)(tempInt1 / -8.9f)); + } + } + else + { + if (vScrollBar1.Maximum > 0) + { + Debug.WriteLine(tempInt1); + if (!(tempInt1 > 0)) + { + Debug.WriteLine("WORKING"); + panel1.Location = new Point(0, tempInt1); + Debug.WriteLine(tempInt1); + } + } + } + } + } + + int prevListValue; + Panel p1; + Label l1; + Label l2; + Label l3; + List PanelList = new List(); + List