Santosh Gurav

Santosh Gurav

  • 1.5k
  • 253
  • 971

Reading Keystrokes Using Windows Service

Oct 16 2018 11:34 AM
Hi Techies,
I have some applications which I want to launch when user presses specific keys from the keyboard, and for this I want to use WndProc method.
I am successful in this in a WinForms application. I want to develop a Windows Service to achieve this.
I get the following errors while trying to use the code in a Windows Service.
1. RegHotKeys.CreateParams : no suitable method found to override
2. RegHotKeys.WndProc(ref Message) : no suitable method found to override
3. ServiceBase does not contain a definition for WndProc
4. ServiceBase does not contain a definition for CreateParams
Following is the code snippet:
  1. protected override void WndProc(ref Message keyPressed)  
  2. {  
  3. Keys keyData = ((Keys)((int)((long)keyPressed.WParam))) | Control.ModifierKeys;  
  4.   
  5. if (keyPressed.LParam.ToInt32() == hotKey1)  
  6. {  
  7. //ACTION 1  
  8. }  
  9. else if (keyPressed.LParam.ToInt32() == hotKey2)  
  10. {  
  11. //ACTION 2  
  12. }  
  13. else if (keyPressed.LParam.ToInt32() == hotKey3)  
  14. {  
  15. //ACTION 3  
  16. }  
  17. else if (keyPressed.LParam.ToInt32() == hotKey4)  
  18. {  
  19. //ACTION 4  
  20. }  
  21.   
  22. base.WndProc(ref keyPressed);  
  23. }  
  24.   
  25. protected override CreateParams CreateParams  
  26. {  
  27. get  
  28. {  
  29. var cp = base.CreateParams;  
  30. cp.ExStyle |= 0x80; // Turn on WS_EX_TOOLWINDOW  
  31. return cp;  
  32. }  
  33. }  
So can anybody suggest what could be the possible solution to this please?