| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> 系统管理编程 >> 实例分析正文
最新推荐 更多内容
VB.Net锁定键盘和鼠标的实例
VB.Net锁定键盘和鼠标的实例
作者:Innovathis    来源:CodeProject     更新时间:2008-1-1

VB.Net锁定键盘和鼠标的实例 乐博网简单翻译一下

'首先必须调用以下方法来实现SendKeys

在这个实例中我们将演示如何让应用程序窗体在执行计算操作的时候自动锁定键盘与鼠标,
等待操作结束再解除锁定.

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);

If such an application window exists or will appear in the given 30 seconds, it will be given the key stroke - 22*22 and then the ENTER special key. If you activate your calculator, you will get the result to this calculation.

  • 上一篇:

  • 下一篇:
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    锁定和解锁文件的实例

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]