+ Reply to Thread
Results 1 to 3 of 3

Turn CAPSLOCK on and off

  1. #1
    Forum Contributor
    Join Date
    09-05-2004
    Location
    Melbourne
    Posts
    193

    Turn CAPSLOCK on and off

    I would love to know how to turn CAPSLOCK on and off using VBA.

    Thanks!

  2. #2
    Forum Contributor
    Join Date
    09-05-2004
    Location
    Melbourne
    Posts
    193
    I found a solution at http://www.excel-center.de/excel/handbuch.php

    go to API no. 11 if you don't read German or don't have a web page translator.

    Cheers!

  3. #3
    Forum Contributor
    Join Date
    09-05-2004
    Location
    Melbourne
    Posts
    193
    Found an even easier way that works for all keys as long as you know their code. For example, CAPSLOCK is &H14.

    Private Sub Workbook_Open()

    SetKeyState &H14, True

    End Sub

    Declare Function GetKeyboardState Lib "user32" _
    (pbKeyState As Byte) As Long
    Declare Function SetKeyboardState Lib "user32" _
    (lppbKeyState As Byte) As Long

    Sub SetKeyState(intKey As Integer, bTurnOn As Boolean)

    ' Retrieve the keyboard state, set the particular
    ' key in which you're interested, and then set
    ' the entire keyboard state back the way it
    ' was, with the one key altered.

    Dim abytBuffer(0 To 255) As Byte

    GetKeyboardState abytBuffer(0)
    abytBuffer(intKey) = CByte(Abs(bTurnOn))
    SetKeyboardState abytBuffer(0)

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1