Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using visual basic 6.0 and I want to desable funtion key F5 for operating system.
VB
Public Class WinControl
        ' This is the function used in order to block the keyboard and mouse:
        Declare Function BlockInput Lib "User32" _
               (ByVal fBlockIt As Boolean) As Boolean
        ' This function will block the keyboard and mouse untill a window with
        ' the specify caption will appear or the given time in seconds has 
        ' past ( 0 seconds - wait forever).
        ' If the window with the caption appears than the given key is send 
        ' to it and the input block is removed.
        Public Shared Function Wait2Send(ByVal caption As String, _
                  ByVal keys As String, ByVal seconds As Integer)
            ' Indicates if the window with the given caption was found
            Dim success As Boolean = False
            ' Start time of the function
            Dim now As DateTime = DateTime.Now
            ' Begining of keyboard and mouse block
            BlockInput(True)

            While (success = False And (DateTime.Now.Subtract(now).Seconds _
                                                   < seconds Or seconds = 0))
                Try
                    ' Activating the window with desired function
                    ' if the window is not found an exception is thrown.
                    AppActivate(caption)
                    ' Sending desired key stroke to the application window
                    SendKeys.SendWait(keys)
                    ' Indicates the window was found and keys sent
                    success = True
                Catch
                    ' Assuming window was not found and sleep for 100 miliseconds
                    System.Threading.Thread.Sleep(100)
                End Try
            End While
            ' Release the keyboard block
            BlockInput(False)
        End Function
    End Class


This code is working but it disables both mouse and keyboard.

I have to desable only F5.

Please give some code or idea.
Thanks in advance
Posted
Updated 7-Oct-11 0:20am
v4
Comments
dasblinkenlight 7-Oct-11 6:13am    
The pattern "block all input, wait for a pop-up, and deliver a click to it" reminds me of viruses and adware. You aren't writing any of these nasty things, right?

Just kidding...
Simon_Whale 7-Oct-11 6:16am    
Are you wanting to block f5 for anything running on the OS or just your application?
singh7pankaj 7-Oct-11 6:47am    
I want to block f5 for anything running on the OS not only for my application
Dalek Dave 7-Oct-11 6:21am    
Edited for Proper Code Block and Spelling and Readability.

Using BlockInput(), You can not diasable the specific key becouse it will block the all input events of the system.
Look Here -> http://msdn.microsoft.com/en-US/library/ms646290.aspx[^]

If you want suspress specific key then handle the events of keyboard
and do the following inside the keyboard input handler

VB
If keyascii = vbKeyF5 then
     keyascii = 0
end if
 
Share this answer
 
Comments
Dalek Dave 7-Oct-11 6:21am    
Spot on!
Simon_Whale 7-Oct-11 6:27am    
good find!
You should direct this question to the author of the BlockImput(Boolean) function, as he is the only person in the world who could potentially know the answer.
 
Share this answer
 
F5 is a refresh button and disabling it WOULD annoy users as it would stop it for their Internet browsers also.

but if you still want to do it I would have a read of this link

How do you disable function key[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900