Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Detecting whether Caps Lock is set

I wonder if anyone can help me with this:

I have written a macro that the user can invoke using a
keyboard shortcut. The issue is that I would like the
macro to do something different depending on whether the
user presses "l" or Shift-"l" (i.e. "L"). Of course, if
the Caps Lock key is on, and the user does not notice, the
actions will be reversed. I'd like to be able, in the
macro, to test whether Caps Lock is set on.

Any thoughts? Sorry if this is a total "duh" question.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Detecting whether Caps Lock is set

Franco,

Try something like

Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As
Long) As Integer

Sub AAA()
Dim Res As Boolean
Res = GetKeyState(vbKeyCapital) And 1
Debug.Print Res 'True is CAPS LOCK, False is not
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Franco Turrinelli" wrote in
message ...
I wonder if anyone can help me with this:

I have written a macro that the user can invoke using a
keyboard shortcut. The issue is that I would like the
macro to do something different depending on whether the
user presses "l" or Shift-"l" (i.e. "L"). Of course, if
the Caps Lock key is on, and the user does not notice, the
actions will be reversed. I'd like to be able, in the
macro, to test whether Caps Lock is set on.

Any thoughts? Sorry if this is a total "duh" question.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Detecting whether Caps Lock is set

For the shift key you van use this

Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Const VK_SHIFT As Integer = &H10 'Shift

Sub test()
If GetKeyState(VK_SHIFT) < 0 Then
MsgBox "You used the Shift key"
Else
MsgBox "You not used the shift key"
End If
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Chip Pearson" wrote in message ...
Franco,

Try something like

Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As
Long) As Integer

Sub AAA()
Dim Res As Boolean
Res = GetKeyState(vbKeyCapital) And 1
Debug.Print Res 'True is CAPS LOCK, False is not
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Franco Turrinelli" wrote in
message ...
I wonder if anyone can help me with this:

I have written a macro that the user can invoke using a
keyboard shortcut. The issue is that I would like the
macro to do something different depending on whether the
user presses "l" or Shift-"l" (i.e. "L"). Of course, if
the Caps Lock key is on, and the user does not notice, the
actions will be reversed. I'd like to be able, in the
macro, to test whether Caps Lock is set on.

Any thoughts? Sorry if this is a total "duh" question.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Detecting whether Caps Lock is set

Thank you both, it works. Now I'll try to understand
exactly why and how . . . ;-)

-----Original Message-----
For the shift key you van use this

Declare Function GetKeyState Lib "user32" (ByVal nVirtKey

As Long) As Integer
Public Const VK_SHIFT As Integer = &H10 'Shift

Sub test()
If GetKeyState(VK_SHIFT) < 0 Then
MsgBox "You used the Shift key"
Else
MsgBox "You not used the shift key"
End If
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Chip Pearson" wrote in message

...
Franco,

Try something like

Declare Function GetKeyState Lib "user32" (ByVal

nVirtKey As
Long) As Integer

Sub AAA()
Dim Res As Boolean
Res = GetKeyState(vbKeyCapital) And 1
Debug.Print Res 'True is CAPS LOCK, False is not
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Franco Turrinelli"

wrote in
message ...
I wonder if anyone can help me with this:

I have written a macro that the user can invoke using

a
keyboard shortcut. The issue is that I would like the
macro to do something different depending on whether

the
user presses "l" or Shift-"l" (i.e. "L"). Of course,

if
the Caps Lock key is on, and the user does not

notice, the
actions will be reversed. I'd like to be able, in the
macro, to test whether Caps Lock is set on.

Any thoughts? Sorry if this is a total "duh"

question.




.

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
How to lock the Ctrl key? (as locking the Shift key w/Caps Lock) Rick-cel Excel Discussion (Misc queries) 2 August 5th 09 06:45 PM
auto caps lock ramzi Excel Discussion (Misc queries) 2 July 25th 08 09:53 PM
is it possible to disable the CAPS LOCK key ? atoach Excel Discussion (Misc queries) 4 July 26th 07 10:45 PM
Caps Lock Franco Turrinelli Excel Programming 0 February 25th 04 03:39 PM
Caps lock Paula Osheroff Excel Programming 2 October 13th 03 10:41 PM


All times are GMT +1. The time now is 09:26 AM.

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

About Us

"It's about Microsoft Excel"