Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 58,285 times

Contents

Related Categories

Simulating User Actions - Keyboard Events

Keyboard Events

This module lets you simulate keyboard events. Many thanks to Rohit Kulshreshtha for this!

Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const KEYEVENTF_EXTENDEDKEY = &H1
Public Const KEYEVENTF_KEYUP = &H2

Public Sub KeyDown(KCC As KeyCodeConstants)
    keybd_event KCC, 0, 0, 0
End Sub

Public Sub KeyUp(KCC As KeyCodeConstants)
    keybd_event KCC, 0, KEYEVENTF_KEYUP, 0
End Sub

Public Sub KeyPress(KCC As KeyCodeConstants)
    KeyDown KCC
    KeyUp KCC
End Sub

Public Sub ShiftOnn()
    KeyDown vbKeyShift
End Sub

Public Sub ShiftOff()
    KeyUp vbKeyShift
End Sub

Public Sub CtrlOnn()
    KeyDown vbKeyControl
End Sub

Public Sub CtrlOff()
    KeyUp vbKeyControl
End Sub

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [68] Simulating User Actions

    Posted by gangstavexx on 29 Aug 2007

    This is col and all and im happy wit all the keys used i it, except for one, y is it that enter is not in the list when i type KeyPress(vbKey?

  • Re: [68] Simulating User Actions

    Posted by cubbuk on 13 Apr 2007

    Hi, is there a C# version of this code, by the way thanks a lot for this code too, it helps me too much.

  • Re: [68] Simulating User Actions

    Posted by Maximus1234 on 13 Sep 2006

    Will this code prevent the screensaver from beeing activated (if I just use the mouse movement now and then)?


    /Max

  • ShiftOn and CtrlOn

    Posted by kc111 on 12 Feb 2005

    It might be a good idea to drop the second 'n' from ShiftOnn and CtrlOnn

  • Help... [edit] Nevermind.

    Posted by MathiasRav on 07 Mar 2004

    I can't make it work.
    I'm using this code:
    [code]Private Sub tMover_Timer()
    Select Case tMover.Tag
    Case 0
    MoveMouse GetCurrentX + 10, GetCurrentY
    tMover.Tag = 1
    Case...