Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DEG DEG is offline
external usenet poster
 
Posts: 6
Default "Caps Lock/Unlock"

Hi Guys and Gals,

Looking for code to lock and unlock caps that will work in both XP and
Vista....anything out there??

Don
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "Caps Lock/Unlock"


This Function checks if caps lock is on


Code:
--------------------
Option Explicit
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

Private Sub x()
Dim lngCapsStatus As Long

lngCapsStatus = GetKeyState(vbKeyCapital)
If lngCapsStatus = 1 Then
MsgBox "The Caps Lock Is On"
Else
MsgBox "The Caps Lock Is Off"
End If
End Sub
--------------------


The following code can be used to switch Caps Lock on and off


O
Code:
--------------------
ption Explicit

Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VK_CAPITAL = &H14
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2


Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

' API declarations:

Private Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long

Private Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

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

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

Public Sub ToggleCapsLock(bTurnOn As Boolean)

'To turn capslock on, set bTurnOn to true
'To turn capslock off, set bTurnOn to false

Dim bytKeys(255) As Byte
Dim bCapsLockOn As Boolean

'Get status of the 256 virtual keys
GetKeyboardState bytKeys(0)

bCapsLockOn = bytKeys(VK_CAPITAL)
Dim typOS As OSVERSIONINFO

If bCapsLockOn < bTurnOn Then 'if current state <
'requested state

If typOS.dwPlatformId = _
VER_PLATFORM_WIN32_WINDOWS Then '=== Win95/98

bytKeys(VK_CAPITAL) = 1
SetKeyboardState bytKeys(0)

Else '=== WinNT/2000

'Simulate Key Press
keybd_event VK_CAPITAL, &H45, _
KEYEVENTF_EXTENDEDKEY Or 0, 0
'Simulate Key Release
keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY _
Or KEYEVENTF_KEYUP, 0
End If
End If


End Sub

Sub switchOn()
ToggleCapsLock (True)
End Sub

Sub switchOff()
ToggleCapsLock (False)
End Sub


--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=94967

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default "Caps Lock/Unlock"

Hi,

Have a look here on how to do it but it seems like a lot of bother to me,
why don't you simple convert to upper & lower case as required using UCASE or
LCASE in you code.

http://support.microsoft.com/kb/177674/EN-US/

Mike

"DEG" wrote:

Hi Guys and Gals,

Looking for code to lock and unlock caps that will work in both XP and
Vista....anything out there??

Don

  #4   Report Post  
Posted to microsoft.public.excel.programming
DEG DEG is offline
external usenet poster
 
Posts: 6
Default "Caps Lock/Unlock"

Hi guys,

Tried to thank you both yesterday for the quick replies but MSN wouldn't
take the reply...so...better late than never...thanks a bunch. Mike your
method worked out great for what I had to do as I didn't have to really lock
the caps, just take data from a combobox and cap it when it was transferred
to the main sheet. But I thank you both...lots of good info...

Have a great weekend,

Don

"Mike H" wrote:

Hi,

Have a look here on how to do it but it seems like a lot of bother to me,
why don't you simple convert to upper & lower case as required using UCASE or
LCASE in you code.

http://support.microsoft.com/kb/177674/EN-US/

Mike

"DEG" wrote:

Hi Guys and Gals,

Looking for code to lock and unlock caps that will work in both XP and
Vista....anything out there??

Don

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Format Excel cells for "all caps", with Office 07? Louisana Jim Excel Discussion (Misc queries) 4 January 24th 10 10:08 PM
Why does the word typed "true" automatically turn to ALL CAPS? sunil New Users to Excel 2 October 31st 06 07:41 AM
How can I use the "Small Caps" Font option in an Excel speadsheet execassist1976 Excel Discussion (Misc queries) 2 October 4th 06 10:40 PM
How to open a "locked for editing" spreadsheet to unlock it? metmart Excel Discussion (Misc queries) 1 April 26th 06 05:55 PM
Visual basic unlock "SORT" function in an EXCEL spreadsheet Jetty Excel Programming 4 July 1st 05 07:43 PM


All times are GMT +1. The time now is 11:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"