Keyboard functions

elgringo56

Well-known Member
Joined
Apr 15, 2002
Messages
869
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
I am trying to turn on or off Keyboard lock under macro control. This morning Ivan gave me this. I know so little, I cant seem to figure out how to use it. Can anyone help?

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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi ElGringo56

Where have you placed this Code?
- Should be in a STD Module

How to want to initiate the code?
- Via commandbutton or upon opening or
some other event.
 
Upvote 0
I dont know what an STD Module is???

I want to initiate it as I move down thru code, or maybe as I open a sheet, hmm, may be better if I did it when I opened the sheets I want caps on. Makes sence to me.
 
Upvote 0
On 2002-05-11 14:11, elgringo56 wrote:
I dont know what an STD Module is???

I want to initiate it as I move down thru code, or maybe as I open a sheet, hmm, may be better if I did it when I opened the sheets I want caps on. Makes sence to me.

To get this to work when you open the workbook then.....

From your Worksheet
1. Press Alt-F11 to display the Visual Basic editor.

2. In the Project Explorer window, find an entry for the Thisworkbook object. If you don't see the Project Explorer window, press Ctrl-R.

3. Double-click on thisworkbook entry in the Project Explorer window.

4. Paste this code here

<pre/>
Private Sub Workbook_Open()
Caps_On
End Sub
</pre>




Is there a reason you want this on ?
If for input reasons then there are other
Options...ie allow users to input THEN convert.....
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,239
Members
448,555
Latest member
RobertJones1986

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