if your problem is detecting the key press then this will work (make a timer with 100 delay then enable it) function: Code: Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer Code: Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If GetAsyncKeyState(Keys.LWin) Then MessageBox.Show("winkey pressed") End If If GetAsyncKeyState(Keys.Up) Then MessageBox.Show("up pressed") End If End Sub
Can't you just set the MaximizeBox property on your form to False? As far as I know, there's no way to prevent resizing via Windows Key + Up by using the KeyDown event of a form because it only sends the Windows key and not the Up button.
thats why i showed him the getasynckeystate function, it will register all key presses even if the program is not in focus EDIT: I think i found what you are looking for (found it on a site and modified it a little for your purpose this will disable the winkeyup on form load and reenable it on form close (uses a low-level hook) tested as working (You may have to go to Project / Properties / Debug and uncheck Enable the Visual Studio Hosting process for it to work while running in Visual Studio), here's the class: Code: Public Class KeyboardJammer Private Delegate Function HookCallback(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer Private Shared HookDelegate As HookCallback Private Shared HookId As Integer Private Const Wh_Keyboard_LL As Integer = 13 Private Shared Function KeyBoardHookProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer 'All keyboard events will be sent here. 'Don't process just pass along. If nCode < 0 Then Return CallNextHookEx(HookId, nCode, wParam, lParam) End If 'Extract the keyboard structure from the lparam 'This will contain the virtual key and any flags. 'This is using the my.computer.keyboard to get the 'flags instead Dim KeyboardSruct As KBDLLHOOKSTRUCT = Marshal.PtrToStructure(lParam, GetType(KBDLLHOOKSTRUCT)) If KeyboardSruct.vkCode = Keys.LWin And Keys.Up Then 'Alt Tab Return 1 End If 'Send the message along Return CallNextHookEx(HookId, nCode, wParam, lParam) End Function Public Shared Sub Jam() 'Add the low level keyboard hook If HookId = 0 Then HookDelegate = AddressOf KeyBoardHookProc HookId = SetWindowsHookEx(Wh_Keyboard_LL, HookDelegate, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly.GetModules()(0)), 0) If HookId = 0 Then MessageBox.Show("there was an error") End If End If End Sub Public Shared Sub UnJam() 'Remove the hook UnhookWindowsHookEx(HookId) End Sub <DllImport("user32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _ Private Shared Function CallNextHookEx( _ ByVal idHook As Integer, _ ByVal nCode As Integer, _ ByVal wParam As IntPtr, _ ByVal lParam As IntPtr) As Integer End Function <DllImport("user32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall, SetLastError:=True)> _ Private Shared Function SetWindowsHookEx( _ ByVal idHook As Integer, _ ByVal HookProc As HookCallback, _ ByVal hInstance As IntPtr, _ ByVal wParam As Integer) As Integer End Function <DllImport("user32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall, SetLastError:=True)> _ Private Shared Function UnhookWindowsHookEx(ByVal idHook As Integer) As Integer End Function Private Structure KBDLLHOOKSTRUCT Public vkCode As Integer Public scanCode As Integer Public flags As Integer Public time As Integer Public dwExtraInfo As IntPtr End Structure End Class you need these imports: Code: Imports System.Runtime.InteropServices Imports System.Reflection to use it just paste these in (do not call them, they automatically are called by form load and close) Code: Private Sub Form1_HandleCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.HandleCreated KeyboardJammer.Jam() End Sub Private Sub Form1_HandleDestroyed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.HandleDestroyed KeyboardJammer.UnJam() End Sub you can add this in a timer with 100 delay to toggle the disabling(e and d): Code: Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If GetAsyncKeyState(Keys.E) Then KeyboardJammer.Jam() End If If GetAsyncKeyState(Keys.D) Then KeyboardJammer.UnJam() End If End Sub I for one have trouble viewing this in this format so here is the project link here don't use their download manager 98% of the credit to:http://www.daniweb.com/software-development/vbnet/threads/359374/disable-alttab-win-key-ctrl-esc-key
during some testing i found that this line Code: If KeyboardSruct.vkCode = Keys.LWin And Keys.Up Then 'Alt Tab Return 1 End If should be broken into 2 such as Code: If KeyboardSruct.vkCode = Keys.LWin Then 'Alt Tab Return 1 End If and Code: If KeyboardSruct.vkCode = Keys.Up Then 'Alt Tab Return 1 End If it seems that it only will jam the first key in an "and" or and "or" statement
i wrote a custom keyboard launcher ( adds my own key combos to launch programs and files) when the hook fires the event i notices that Shift + L for example came up like ShiftL now those hooks work the same way If WINU ( shows up like that in the hook) is fired then react to your liking...