Note that there are some explanatory texts on larger screens.

plurals
  1. PODisable keyboard using c#
    primarykey
    data
    text
    <p>I'm writing a program which is a webbrowser and disable all the keyboard shortcuts and keys. It is working but not perfectly. i found a thread where i got the code:</p> <p><a href="https://stackoverflow.com/questions/1175675/blocking-shortcut-keys-using-c-sharp">Blocking shortcut keys using c#</a></p> <p>And my problem is: everytime i open the program, first i have to click in the window or use a shortcut and click in the window again. and after that, it works. but it have to work when i open it so i don't have to click two times...</p> <p>somebody got an idea?</p> <p>cheers</p> <p>EDIT: Okay. I try to explain my problem in another way:</p> <p>First I open the program. And then I should not be able to press any keys like Win+Tab etc. But I am still able to press keys. Then if I click in the window of my program, press a key and click in the window again, it works. But i want that the program works when I open it so I don't have to click in the window first. I got some code here:</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Diagnostics; namespace Browser { public partial class Form1 : Telerik.WinControls.UI.RadForm { public Form1() { InitializeComponent(); } private delegate int LowLevelKeyboardProcDelegate(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam); [DllImport("user32.dll", EntryPoint = "SetWindowsHookExA", CharSet = CharSet.Ansi)] private static extern int SetWindowsHookEx( int idHook, LowLevelKeyboardProcDelegate lpfn, int hMod, int dwThreadId); [DllImport("user32.dll")] private static extern int UnhookWindowsHookEx(int hHook); [DllImport("user32.dll", EntryPoint = "CallNextHookEx", CharSet = CharSet.Ansi)] private static extern int CallNextHookEx( int hHook, int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam); const int WH_KEYBOARD_LL = 13; private int intLLKey; private KBDLLHOOKSTRUCT lParam; private struct KBDLLHOOKSTRUCT { public int vkCode; int scanCode; public int flags; int time; int dwExtraInfo; } private int LowLevelKeyboardProc( int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam) { bool blnEat = false; switch (wParam) { case 256: case 257: case 260: case 261: //Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key if (((lParam.vkCode == 9) &amp;&amp; (lParam.flags == 32)) || ((lParam.vkCode == 27) &amp;&amp; (lParam.flags == 32)) || ((lParam.vkCode == 27) &amp;&amp; (lParam.flags == 0)) || ((lParam.vkCode == 91) &amp;&amp; (lParam.flags == 1)) || ((lParam.vkCode == 92) &amp;&amp; (lParam.flags == 1)) || ((true) &amp;&amp; (lParam.flags == 32))) { blnEat = true; } break; } if (blnEat) return 1; else return CallNextHookEx(0, nCode, wParam, ref lParam); } private void KeyboardHook(object sender, EventArgs e) { intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, new LowLevelKeyboardProcDelegate(LowLevelKeyboardProc), System.Runtime.InteropServices.Marshal.GetHINSTANCE( System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]).ToInt32(), 0); } private void ReleaseKeyboardHook() { intLLKey = UnhookWindowsHookEx(intLLKey); } private void Form1_Load(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; } private void webBrowser1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { KeyboardHook(this, e); } } } </code></pre> <p>I hope you know what I mean now Cheers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload