locked
key hooking RRS feed

  • Question

  • need help to detect my volume button on my n53sn (win 7),

     I have tried http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx

    without success.

    help is appreciated, thanks in advances !!

    Thursday, July 28, 2011 2:50 PM

Answers

  • but I want to do the Same Thing as the software does, I do not want to gothe easy route  : )


    The easy route may be best.  I don't know how many people around here have that brand of computer who would be able to help you.  Not many, I would expect.

    Besides, managed code is inappropriate for writing hardware device drivers.  You would need to use unmanaged code to properly interact with the hardware with degree of control that you would need.  See this link for the tip of the iceberg.  Good luck.

    Windows Driver Kit

    Even with that kit, you will still need to consult the hardware manufacturer for stuff like hardware addresses and such.

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/


    • Marked as answer by Cookie Luo Thursday, August 4, 2011 7:05 AM
    Sunday, July 31, 2011 6:56 PM

All replies

  • Try using Accelerators and in the Key enumeration there are keys like VolumeUp or VolumeDown.
    Thursday, July 28, 2011 5:05 PM
  • u need to play with win32 library for controlling such things and u will get many refrences when u will google it :)
    [Please Mark the Answers if it is the solution of your problem]
    Thursday, July 28, 2011 7:44 PM
  • hello


    I want to catch the event when I press the (volume up, volume down, mute, play / pause) on my notebook ASUSn53sn (win 7).

    I think it is not regular buttons, because they stop workingwhen I removed a program

      thanks in advance! ! !


    • Merged by Rudedog2 Friday, July 29, 2011 10:27 PM duplicate post
    Friday, July 29, 2011 9:42 PM
  • u need to play with win32 library for controlling such things and u will get many refrences when u will google it :)
    [Please Mark the Answers if it is the solution of your problem]

    I do not know what it can be called. so I do not know what to google : ( 

    more help is appreciated

    Friday, July 29, 2011 9:55 PM
  • Place this code in a form with a TextBox and a Label.

      public partial class Form1 : Form
      {
        private const int WM_KEYDOWN = 0x0100; // 256
        private const int WM_KEYUP = 0X101; // 257
        private const int WM_CHAR = 0x102; // 258
        private const int WM_DEADCHAR = 0x103; // 259
        private const int WM_SYSKEYDOWN = 0x104; // 260
        private const int WM_SYSKEYUP = 0x105; // 261
        private const int WM_SYSCHAR = 0x0106; // 262
    
        public Form1()
        {
          InitializeComponent();
        }
    
        // put mouse cursor in a textbox to see keys as they are typed.
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
          this.label1.Text = "Last Keypress was " + keyData.ToString();
          //
          // was Message a keypress?, this method should always see 256 anyway
          if (msg.Msg == 256) // OS always sends 256, user code sends ???
          {
            switch (keyData)
            {
              case Keys.Control | Keys.A:
                this.label1.Text = "Ctrl-A was pressed.";
                break;
              case Keys.Control | Keys.Shift | Keys.U:
                this.label1.Text = "Ctrl-Shift-U was pressed.";
                break;
              case Keys.Up: // Keys.Down, Keys.Right, Keys.Left
                this.Text = "Up Arrow was pressed.";
                break;
              //case Keys.Shift | Keys.ShiftKey | Keys.Control:
              //case Keys.ControlKey | Keys.Control:
              //case Keys.ShiftKey | Keys.Shift:
              //  break; // code above ignores modifiers-only key presses
              default:
                break;
            }
          }
          return base.ProcessCmdKey(ref msg, keyData);
        }
        //protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        //{
        //  if (msg.Msg == 256)
        //  {
        //    if (keyData == (Keys.Control | Keys.S))
        //    {
        //      MessageBox.Show("CTRL-S was pressed! ");
        //    }
        //  }
        //  return base.ProcessCmdKey(ref msg, keyData);
        //}
      }
    
    
    

    Rudy   =8^D 


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Friday, July 29, 2011 10:25 PM
  • your code works , but it does not work on the keys I want.
    I do not think they are standard keys.

     

    // I tested 
     protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
          System.Console.WriteLine( msg.ToString() + " " + keyData.ToString());
          return base.ProcessCmdKey(ref msg, keyData);
        }


    Friday, July 29, 2011 10:44 PM
  • You mentioned deleting a program.  Perhaps you need that driver/software re-installed. 

    http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/162aa4b6-4e28-433a-826c-63ecfdd1129b

    Take a look at that thread for a low level keyboard hook, to see if the OS is responding to the key presses in any way.

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Saturday, July 30, 2011 11:43 AM
  • no, it does not respond, what are the other options (not necessarily C #) ?
    Sunday, July 31, 2011 2:35 PM
  • ..... they stop workingwhen I removed a program

      thanks in advance! ! !



    No reponses, huh.  Not good. 

    Well.  Like I said, you will need to re-install that piece of software.  Consult the hardware manufacturer or software vendor.


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Sunday, July 31, 2011 3:45 PM
  • but I want to do the Same Thing as the software does, I do not want to gothe easy route  : )
    Sunday, July 31, 2011 3:50 PM
  • but I want to do the Same Thing as the software does, I do not want to gothe easy route  : )


    The easy route may be best.  I don't know how many people around here have that brand of computer who would be able to help you.  Not many, I would expect.

    Besides, managed code is inappropriate for writing hardware device drivers.  You would need to use unmanaged code to properly interact with the hardware with degree of control that you would need.  See this link for the tip of the iceberg.  Good luck.

    Windows Driver Kit

    Even with that kit, you will still need to consult the hardware manufacturer for stuff like hardware addresses and such.

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/


    • Marked as answer by Cookie Luo Thursday, August 4, 2011 7:05 AM
    Sunday, July 31, 2011 6:56 PM