How to register multiple global hot-keys in C#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • scriptick
    New Member
    • Apr 2013
    • 15

    How to register multiple global hot-keys in C#?

    Hi everyone,
    I want to register multiple global hotkeys. CTRL+A , SHIFT+B etc etc etc.
    I want to more clear :
    If i pressed : CTRL+A then a message will show (MessageBox.Sho w("Pavel,Tangal ")
    If i pressed SHIFT+B then minimize application.
    If i pressed SHIFT+C maximize application.

    I found a solution on internet related to it but i can not add here modifiers keys like : CTRL or SHIFT or ALT etc.

    It is like : A,B,C,D

    Sorry for my English.

    Pls see my project sample and pls help me. (on attach)
    Thanks
    Attached Files
  • vijay6
    New Member
    • Mar 2010
    • 158

    #2
    Hey scriptick, you can use 'KeyDown' event for your form like as follows,

    Code:
    void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Control & e.KeyCode == Keys.A)
        {
            MessageBox.Show("Pavel,Tangal");
        }
    	else if (e.Shift & e.KeyCode == Keys.B)
        {
            this.WindowState = FormWindowState.Minimized;
        }
        else if(e.Shift & e.KeyCode == Keys.C)
        {
            this.WindowState = FormWindowState.Maximized;
        }
    }

    Note: This code ll work only if 'Form1' had focus.

    Comment

    • scriptick
      New Member
      • Apr 2013
      • 15

      #3
      Originally posted by vijay6
      Hey scriptick, you can use 'KeyDown' event for your form like as follows,

      Code:
      void Form1_KeyDown(object sender, KeyEventArgs e)
      {
          if (e.Control & e.KeyCode == Keys.A)
          {
              MessageBox.Show("Pavel,Tangal");
          }
      	else if (e.Shift & e.KeyCode == Keys.B)
          {
              this.WindowState = FormWindowState.Minimized;
          }
          else if(e.Shift & e.KeyCode == Keys.C)
          {
              this.WindowState = FormWindowState.Maximized;
          }
      }

      Note: This code ll work only if 'Form1' had focus.
      thank you very much for your nice repl.
      but I want to do it from anywhere. if my app is minimize then is it work? I want something like ctrl + a in window is select all. something like that.

      anyway sorry for eng.


      thanks again

      Comment

      • vijay6
        New Member
        • Mar 2010
        • 158

        #4
        Hey scriptick, I already told you "This code ll work only if 'Form1' had focus." Are you trying to create any malicious software?

        Comment

        • scriptick
          New Member
          • Apr 2013
          • 15

          #5
          Hello vijay6, Thank you a lot for your again reply. Many many thanks.

          Anyway I am not creating malicious software. I want to made game trainer with it. I already made some game trainer with this methood.
          On GTA Vice City :
          If Press CTRL+ALT+1 = SendKeys.Send(" LeaveMeAlone");

          Before i do it in LUA.But now i want to do it on C#.NET.

          Nothing Else.

          Thank you !!!

          Comment

          • vijay6
            New Member
            • Mar 2010
            • 158

            #6
            I want to made game trainer with it.

            Hey scriptick, Well! this is interesting!!! You can use the code which is in the below link for your trainer. All you have to do is replace the 'gHook_KeyDown' event by the below code.

            Global KeyBoard Hook C#

            Code:
            public void gHook_KeyDown(object sender, KeyEventArgs e)
            {
            	if ((lastKey == 162 || lastKey == 163) && e.KeyValue == 65)
            	{
            		MessageBox.Show("Pavel,Tangal");
            	}
            
            	else if ((lastKey == 160 || lastKey == 161) && e.KeyValue == 66)
            	{
            		this.WindowState = FormWindowState.Minimized;
            	}
            
            	else if ((lastKey == 160 || lastKey == 161) && e.KeyValue == 67)
            	{
            		this.WindowState = FormWindowState.Maximized;
            	}
            
            	lastKey = e.KeyValue;
            }

            Note:

            lastKey - Integer type class variable.

            65 refers to A.
            66 refers to B.
            67 refers to C.
            160 refers to Left Shift.
            161 refers to Right Shift.
            162 refers to Left Ctrl.
            163 refers to Right Ctrl.

            Before i do it in LUA.

            Can you share your 'GTA Vice City' trainer with others (me)?


            Hey, don't forgot to share your trainer!!!

            Comment

            • scriptick
              New Member
              • Apr 2013
              • 15

              #7
              Hello vijay6 thank you verrrrrrrreey much bro for your help !!!! I am very happy to you. off course I am going to send you that when I sit on pc.

              anyway thanks a lot again.
              if you need me anytime pls PM me. I am ready to help you anyway.

              thank you very much!!!

              Comment

              • zmbd
                Recognized Expert Moderator Expert
                • Mar 2012
                • 5501

                #8
                @OP
                THe fact that you want this to happen outside of your program's focus/ownership makes this is potentially dangerous code and follows inline with a more recent thread of yours...

                Asking for help to write potentially malicious code is against site policy and may result in the suspension of your account.

                I respectfully ask that you clearly state the intent of this project.

                -ZMBD

                Comment

                Working...