Skip to main content
Recompensa finalizada con 50 de reputación otorgada por an-tet
Mejorar
Origen Enlace
Dany
  • 316
  • 1
  • 3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {

        //Declaramos nuestras API y Constantes Necesarias
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
        private const int WM_HOTKEY = 0x0312;

        enum KeyModifier
        {
            None = 0,
            Alt = 1,
            Control = 2,
            Shift = 4,
            WinKey = 8
        }

        //Sobrescribimos nuestro procedimiento WndProc para darle unan nueva 
        funcionalidad y poder detectar el evento del teclado registrado.
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_HOTKEY) //Detectamos el evento
            {
                Visible =true; //Mostrar Formulario
            }
        }

 
        public Form1()
        {
            InitializeComponent();
            int id = 0;   //dejar por defecto 
             //Registramos El evento asociado al iniciar el formulario
            RegisterHotKey(this.Handle, id, (int)KeyModifier.Control, Keys.A.GetHashCode());       // Registar Ctrl + A 

        }

        private void ExampleForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            UnregisterHotKey(this.Handle, 0);       // Anular Registro
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Visible = false;
        }
    }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
        private const int WM_HOTKEY = 0x0312;

        enum KeyModifier
        {
            None = 0,
            Alt = 1,
            Control = 2,
            Shift = 4,
            WinKey = 8
        }


        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_HOTKEY)
            {
                Visible =true; //Mostrar Formulario
            }
        }

 
        public Form1()
        {
            InitializeComponent();
            int id = 0;   
            RegisterHotKey(this.Handle, id, (int)KeyModifier.Control, Keys.A.GetHashCode());       // Registar Ctrl + A 

        }

        private void ExampleForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            UnregisterHotKey(this.Handle, 0);       // Anular Registro
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Visible = false;
        }
    }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {

        //Declaramos nuestras API y Constantes Necesarias
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
        private const int WM_HOTKEY = 0x0312;

        enum KeyModifier
        {
            None = 0,
            Alt = 1,
            Control = 2,
            Shift = 4,
            WinKey = 8
        }

        //Sobrescribimos nuestro procedimiento WndProc para darle unan nueva 
        funcionalidad y poder detectar el evento del teclado registrado.
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_HOTKEY) //Detectamos el evento
            {
                Visible =true; //Mostrar Formulario
            }
        }

 
        public Form1()
        {
            InitializeComponent();
            int id = 0;   //dejar por defecto 
             //Registramos El evento asociado al iniciar el formulario
            RegisterHotKey(this.Handle, id, (int)KeyModifier.Control, Keys.A.GetHashCode());       // Registar Ctrl + A 

        }

        private void ExampleForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            UnregisterHotKey(this.Handle, 0);       // Anular Registro
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Visible = false;
        }
    }
}

mejora
Origen Enlace
Dany
  • 316
  • 1
  • 3

Para lograr esto debesSi estas sobre plataforma Windows puedes usar el APIla función del API de Windows RegisterHotKey

Para lograr esto debes usar el API de Windows RegisterHotKey

Si estas sobre plataforma Windows puedes usar la función del API de Windows RegisterHotKey

Origen Enlace
Dany
  • 316
  • 1
  • 3

Para lograr esto debes usar el API de Windows RegisterHotKey

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
        private const int WM_HOTKEY = 0x0312;

        enum KeyModifier
        {
            None = 0,
            Alt = 1,
            Control = 2,
            Shift = 4,
            WinKey = 8
        }


        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_HOTKEY)
            {
                Visible =true; //Mostrar Formulario
            }
        }

 
        public Form1()
        {
            InitializeComponent();
            int id = 0;   
            RegisterHotKey(this.Handle, id, (int)KeyModifier.Control, Keys.A.GetHashCode());       // Registar Ctrl + A 

        }

        private void ExampleForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            UnregisterHotKey(this.Handle, 0);       // Anular Registro
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Visible = false;
        }
    }
}