Setting Keyboard Functions

elgringo56

Well-known Member
Joined
Apr 15, 2002
Messages
869
Good morning, everyone. I was wondering if any one knew of a way to set, under macro control, the "Caps Lock" function on the keyboard?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
On 2002-05-11 06:37, elgringo56 wrote:
Good morning, everyone. I was wondering if any one knew of a way to set, under macro control, the "Caps Lock" function on the keyboard?
If you mean Turn caps Lock On/Off then you
need some APIs<pre/>
Option Explicit
Private Const VK_CAPITAL = &H14

Private Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type

Private kbArray As KeyboardBytes
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
Private Declare Function GetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
Private Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long

Sub Caps_On()
GetKeyboardState kbArray
kbArray.kbByte(VK_CAPITAL) = 1
SetKeyboardState kbArray
MsgBox "Caps Lock is On"
End Sub


Sub Caps_Off()
GetKeyboardState kbArray
kbArray.kbByte(VK_CAPITAL) = 0
SetKeyboardState kbArray
MsgBox "Caps Lock is Off"
End Sub

Sub Toggle_OnOff()
GetKeyboardState kbArray
kbArray.kbByte(VK_CAPITAL) = Not (kbArray.kbByte(VK_CAPITAL))
SetKeyboardState kbArray
MsgBox "Caps Lock is On:= " & Not (kbArray.kbByte(VK_CAPITAL) = 0)
End Sub</pre>


_________________
Kind Regards,<font size=+2><font color="red"> I<font color="blue">van<font color="red"> F M</font color="blue">oala</font>
comput15.gif
<MARQUEE>Have a Nice day
sun.gif
</MARQUEE>
This message was edited by Ivan F Moala on 2002-05-11 06:57
 
Upvote 0
Alternatively, if you just want to force all input to be capitals :-

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Application.EnableEvents = False
For Each cell In Selection
If cell.HasFormula = False Then
cell.Value = UCase(cell.Value)
End If
Next
Application.EnableEvents = True
End Sub
 
Upvote 0
WOW! Thanks, guys. I am a novice so I will have to mull both of these over for a bit to see if I can understand them. Geez, and I thought there would be something simple like ActiveSheet.CapsLockOn or ActiveSheet.CapsLockOff. LOL, silly me thinking that might happen.
 
Upvote 0
Ivan, I'm trying to figgure out how to plug all or part of this into my macro and make it do something. There is much I do not know about programing and VB. Learning by trial and error. Mostly error.
 
Upvote 0
On 2002-05-11 07:41, elgringo56 wrote:
Ivan, I'm trying to figgure out how to plug all or part of this into my macro and make it do something. There is much I do not know about programing and VB. Learning by trial and error. Mostly error.

What do you want to do AND
What code do you have that you want to modify

If I can help then Post.....
 
Upvote 0
Well, I am trying to figgure out this code you gave me for turning on and off caps lock, but I get an error on it as it is. Not sure what I am doing here
 
Upvote 0
What I did was open a new workbook, then make a simple select macro. Then I copied pasted what you gave me into it and tried to run it. It gave me a complie error. Now trying to figgure out just what it is
 
Upvote 0
Could you not also use the Sendkeys vb command for the desired effect ?

i.e. Sendkeys "CAPS LOCK" ,True

Which can also be used for such keys as :BACKSPACE,BREAK,CAPS LOCK,DEL,DOWN ARROW,END,ENTER,ESC,HELP,HOME,INS or INSERT,LEFT ARROW,NUM LOCK,PAGE DOWN,PAGE UP,PRINT SCREEN,RIGHT ARROW,SCROLL LOCK,TAB,UP ARROW ,F1-F12
This message was edited by nimrod on 2002-05-11 08:50
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top