 |
|
 |
' must have this in order to use the SendKeys function
Imports System.Windows.Forms
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
|
|
|
|
 |
|
 |
today and on yesterday my keyboard has been locked when i return to my desk to unlock it i simply disconnect plug end of mouse cord and insert it back in, this seems to be some sort of office prank or my mouse cord is going bad. how do you lock and unlock mouse and key pad without pulling the plug--help.
|
|
|
|
 |
|
 |
Hi! I want to use my laptop to display a continuous video at a tradeshow booth.
I would like to disable the keyboard and touchpad, so that passers by will not be able to interrupt the video loop or compromise my system.
It would be great to be able to enable the system again with a short pin number or password.
Any suggestions?
Thanks,
Jimmy
|
|
|
|
 |
|
 |
Im using windows 2003 server! I add a buttom on a form to test this code,the sendkey send the text very fast after activation the window! when i clicked very fast on my buttom several times, i saw the text appeard on the activated window.
just i add this bellow code befor sendkey to make a delay, then everything is fine!
System.Threading.Thread.Sleep(100)
thank you man you saved me!
www.istru.com a place to meet a friend.
|
|
|
|
 |
|
 |
this doesn't actually PREVENT ctrn+alt+del, but offers an effective alternative
just copy and paste directly into your code
and add to the load event
'on load event add:
't.interval = 1
't.enabled = true
'when the timer is ticking, just use BlockInput(true)
'and the input will always be blocked.
'make sure you have a way to re-enable input after you start the timer!
'make sure you have a way to re-enable input after you start the timer!
'make sure you have a way to re-enable input after you start the timer!
'create a timer to see if taskmanager is running
Friend WithEvents t as new timer
Private Sub t(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t
'Check to see if taskmgr is running (task manager)
If ProcessRunning("taskmgr") = True Then
'Create a process equal to taskmgr
Dim prc() As Process = Process.GetProcessesByName("taskmgr")
Dim i As Integer = 0
'run through each instance of the task manager and kill it
For i = 0 To UBound(prc)
prc(i).Kill()
Next
End If
End Sub
'this function simply checks to see if a program is running
Private Function ProcessRunning(ByVal ProcessName As String) As Boolean
Dim p() As Process = Process.GetProcessesByName(ProcessName)
If p.Length > 0 Then
Return True
End If
Return False
End Function
'on load event add:
't.interval = 1
't.enabled = true
'another way to do it is by threading but for simplicity i used a timer
|
|
|
|
 |
|
 |
It's a very sloppy way of doing it but you can call the code above with the following line:
WinControl.Wait2Send("Windows Task Manager", "{ESC}", 0)
and then when the user pressed CTRL+ALT+DEL the Windows task manager instantly gets passed the input ESC and closes and it happens so quick the user won't notice!
M
|
|
|
|
 |
|
 |
Hi,
I used the code (see below) of your page in VB.Net 2003,
The Next line isn't acceptet by VB.Net 2003
it gives the next comment :'Imports' statements must precede any declarations.
Becouse i am a beginner i do't know what this means
Can you tell me how to solve this problem?
Thanks a lot
Simon
Code Source : "http://www.codeproject.com/vb/net/LockKeyboard.asp"
' must have this in order to use the SendKeys function
Imports System.Windows.Forms
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
WinControl.Wait2Send("Calculator","22*22{ENTER}",30);
|
|
|
|
 |
|
 |
I need to lock keyboard (mouse optional) input for "other" applications, using my application.
Any suggestions on how i can do this?
thanks
|
|
|
|
 |
|
 |
if you know the code , how can i make a keylogger in VB.NET ??
hi i love VB.NET
|
|
|
|
 |
|
 |
Can I lock the keys ctrl + alt + del?
|
|
|
|
 |
|
 |
i am also disappointed to find that ctrl alt del still works and unblocks input as well. please respond to your feedback and make the necessary revisions in your code. we are all counting on you!
|
|
|
|
 |
|
 |
Don't blame the author for this problem. If you read the description of the BlockInput API on the MSDN, you will see it is by design.
If you want to lock Ctrl-Alt-Delete, or the keyboard completely, take a look at this page:
http://www.sysint.no/en/Download.aspx[^]
|
|
|
|
 |
|
 |
Ive been using the sendkeys class for some time now on different systems and I found that certain systems will send the keystrokes too fast and the application will error out with incorrect keystrokes even when using the sendwait method. In particlular newer dell laptops using wireless connection. Have you found similar results and do you have any suggestions to get around this problem.
|
|
|
|
 |
|
 |
Try SendKeys.Flush() immediately after the AppActivate(caption) line as shown below:
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)
SendKeys.Flush()
' 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
|
|
|
|
 |
|
 |
Is this code only applicable for Windows XP? So is there anything that can be used such that it's usable for other windows versions as well?
|
|
|
|
 |
|
 |
msdn refrences says that windows 98 is compatible, have to test
|
|
|
|
 |
|
 |
How to lock and unlock keyboard and mouse in ME windows?
|
|
|
|
 |
|
 |
Is there a way to unloack the input based on a certain key combination being entered?? I know ctrl+alt+delete can do it. But is there a way I can listen to the keystrokes entered even though they are blocked???
strange question i know
Many thanks
|
|
|
|
 |
|
|
 |