Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using Utilities;
- namespace Visor
- {
- public partial class Form1 : Form
- {
- #region Constants
- private const int SW_HIDE = 0;
- private const int SW_SHOWNORMAL = 1;
- private const int SW_SHOW = 5;
- #endregion Constants
- #region APIs
- [System.Runtime.InteropServices.DllImport("user32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
- private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [System.Runtime.InteropServices.DllImport("user32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
- private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- private static extern bool SetForegroundWindow(IntPtr hwnd);
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- private static extern IntPtr SetFocus(IntPtr hwnd);
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- internal static extern int AttachThreadInput(int idAttach, int idAttachTo, bool fAttach);
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- private static extern IntPtr GetFocus();
- #endregion APIs
- // Declare global key hook object
- private globalKeyboardHook ghk = new globalKeyboardHook();
- // bool to track if console is hidden or visible
- private bool isHidden = false;
- public void ShowApp()
- {
- IntPtr h = FindWindow(null, "C:\\Windows\\system32\\cmd.exe");
- ShowWindow(h, SW_SHOW);
- //EnableWindow(h, true);
- isHidden = false;
- // set focus to console window
- SetForegroundWindow(h);
- System.Diagnostics.Debug.WriteLine(h);
- }
- public void HideApp()
- {
- IntPtr h = FindWindow(null, "C:\\Windows\\system32\\cmd.exe");
- ShowWindow(h, SW_HIDE);
- isHidden = true;
- }
- public Form1()
- {
- // add hooks for tilde
- ghk.HookedKeys.Add(Keys.Oemtilde);
- ghk.KeyDown += new KeyEventHandler(ghk_KeyDown);
- ghk.KeyUp += new KeyEventHandler(ghk_KeyUp);
- InitializeComponent();
- }
- void ghk_KeyDown(object sender, KeyEventArgs e)
- {
- System.Diagnostics.Debug.WriteLine("Down\t" + e.KeyCode.ToString());
- e.Handled = true;
- }
- void ghk_KeyUp(object sender, KeyEventArgs e)
- {
- System.Diagnostics.Debug.WriteLine("Up\t" + e.KeyCode.ToString());
- e.Handled = true;
- if (isHidden == false)
- HideApp();
- else
- ShowApp();
- }
- private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- ShowApp();
- }
- private void Form1_Resize(object sender, System.EventArgs e)
- {
- if (FormWindowState.Minimized == WindowState)
- Hide();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- Visible = false;
- ShowInTaskbar = false;
- Process runExe = new Process();
- runExe.StartInfo.FileName = "cmd.exe";
- Process.Start("cmd.exe");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement