locked
Prevent users from rotating the screen - Keyboard hook? RRS feed

  • Question

  • Hi,
     
    I want to prevent users from using keyboard keys like Ctrl Alt and arrow keys pressed together, which rotates the screen.
    How can I do that ?

    When a user presses Ctrl+Alt+<- Left arrow key the screen is rotated by 90 degrees anticlockwise.

    How should I do this in C#.net?

    Thanks,

    Aseem Chiplonkar
    Software engineer
    Cedara Software
    Thursday, August 7, 2008 11:48 AM

Answers

  • You could try messing with SetWindowsHookEx().  It probably won't work well, WH_KEYBOARD_LL is the only option you got and it is not well suited to disable keys.  Far simpler would be to just uninstall or disable the Pivot software that does this, it is horribly destabilizing anyway.  If the user actually likes pivoting the screen, she won't think much of your fix.
    Hans Passant.
    • Marked as answer by jack 321 Wednesday, August 13, 2008 2:38 AM
    • Marked as answer by jack 321 Wednesday, August 13, 2008 2:38 AM
    Monday, August 11, 2008 11:17 AM

All replies

  • Hi,

    I'm not sure what you mean by:

    "When a user presses Ctrl+Alt+<- Left arrow key the screen is rotated by 90 degrees anticlockwise."

    Does you c# application do that or you have some 3rd party s/w which does that?

    Anyway if you want to avoid the same, then handle your form KeyDown, KeyUp events, check for the key combination and say  e.Handled = true. This will avoid the OS processing this user action.

    regards,
    • Marked as answer by jack 321 Monday, August 11, 2008 6:08 AM
    • Unmarked as answer by Aseem Chiplonkar Monday, August 11, 2008 7:12 AM
    Thursday, August 7, 2008 12:00 PM
  • Hello,

    No. my application does not rotate the screen. Its like one of the function keys like Alt+tab.

    I wanted to know how we can lock some of the keyboard keys through the lifetime of your C# application?

    Meaning, when I am running my application, I will lock the keys say, Alt+Ctrl+arrow key from working.

    Your solution does not work if I lose focus from my application.
    KeyDown,KeyUp events are application specific, I want something global on a OS level.

    Thanks,
    Aseem Chiplonkar
    Monday, August 11, 2008 7:15 AM
  • You could try messing with SetWindowsHookEx().  It probably won't work well, WH_KEYBOARD_LL is the only option you got and it is not well suited to disable keys.  Far simpler would be to just uninstall or disable the Pivot software that does this, it is horribly destabilizing anyway.  If the user actually likes pivoting the screen, she won't think much of your fix.
    Hans Passant.
    • Marked as answer by jack 321 Wednesday, August 13, 2008 2:38 AM
    • Marked as answer by jack 321 Wednesday, August 13, 2008 2:38 AM
    Monday, August 11, 2008 11:17 AM