473,419 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

how on the caps key

chandru8
145 100+
Hi everyone .
Can anyone help me how on the caps key through coding?
Nov 27 '07 #1
3 1061
9815402440
180 100+
Hi

Open new standard exe project. Create a command button (command1) on form1 add following code in the form's code window.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. ' Declare Type for API call:
  3. Private Type OSVERSIONINFO
  4. dwOSVersionInfoSize As Long
  5. dwMajorVersion As Long
  6. dwMinorVersion As Long
  7. dwBuildNumber As Long
  8. dwPlatformId As Long
  9. szCSDVersion As String * 128   '  Maintenance string for PSS usage
  10. End Type
  11.  
  12. ' API declarations:
  13.  
  14. Private Declare Function GetVersionEx Lib "kernel32" _
  15.  Alias "GetVersionExA" _
  16.  (lpVersionInformation As OSVERSIONINFO) As Long
  17.  
  18. Private Declare Sub keybd_event Lib "user32" _
  19.  (ByVal bVk As Byte, _
  20.   ByVal bScan As Byte, _
  21.   ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
  22.  
  23. Private Declare Function GetKeyboardState Lib "user32" _
  24.  (pbKeyState As Byte) As Long
  25.  
  26. Private Declare Function SetKeyboardState Lib "user32" _
  27.  (lppbKeyState As Byte) As Long
  28.  
  29. ' Constant declarations:
  30. Const VK_NUMLOCK = &H90
  31. Const VK_SCROLL = &H91
  32. Const VK_CAPITAL = &H14
  33. Const KEYEVENTF_EXTENDEDKEY = &H1
  34. Const KEYEVENTF_KEYUP = &H2
  35. Const VER_PLATFORM_WIN32_NT = 2
  36. Const VER_PLATFORM_WIN32_WINDOWS = 1
  37.  
  38. Private Sub Command1_Click()
  39.       Dim o As OSVERSIONINFO
  40.       Dim NumLockState As Boolean
  41.       Dim ScrollLockState As Boolean
  42.       Dim CapsLockState As Boolean
  43.  
  44.       o.dwOSVersionInfoSize = Len(o)
  45.       GetVersionEx o
  46.       Dim keys(0 To 255) As Byte
  47.       GetKeyboardState keys(0)
  48.  
  49.       ' NumLock handling:
  50.       NumLockState = keys(VK_NUMLOCK)
  51.       If NumLockState <> True Then    'Turn numlock on
  52.         If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then  '=== Win95/98
  53.  
  54.           keys(VK_NUMLOCK) = 1
  55.           SetKeyboardState keys(0)
  56.         ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then   '=== WinNT
  57.         'Simulate Key Press
  58.           keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
  59.         'Simulate Key Release
  60.           keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY _
  61.              Or KEYEVENTF_KEYUP, 0
  62.         End If
  63.       End If
  64.  
  65.       ' CapsLock handling:
  66.       CapsLockState = keys(VK_CAPITAL)
  67.       If CapsLockState <> True Then    'Turn capslock on
  68.         If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then  '=== Win95/98
  69.           keys(VK_CAPITAL) = 1
  70.           SetKeyboardState keys(0)
  71.         ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then   '=== WinNT
  72.         'Simulate Key Press
  73.           keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
  74.         'Simulate Key Release
  75.           keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY _
  76.              Or KEYEVENTF_KEYUP, 0
  77.         End If
  78.       End If
  79.  
  80.       ' ScrollLock handling:
  81.       ScrollLockState = keys(VK_SCROLL)
  82.       If ScrollLockState <> True Then    'Turn Scroll lock on
  83.         If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then  '=== Win95/98
  84.           keys(VK_SCROLL) = 1
  85.           SetKeyboardState keys(0)
  86.         ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then   '=== WinNT
  87.         'Simulate Key Press
  88.           keybd_event VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
  89.         'Simulate Key Release
  90.           keybd_event VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY _
  91.             Or KEYEVENTF_KEYUP, 0
  92.         End If
  93.       End If
  94. End Sub

Regards
manpreet singh dhillon hoshiarpur
Nov 27 '07 #2
Killer42
8,435 Expert 8TB
Thanks, Manpreet. But it might help if chandru8 could tell us what the actual question is.
Nov 27 '07 #3
chandru8
145 100+
Thanks, Manpreet
thanks for your kindly help
Nov 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Robert | last post by:
Hi! I was wondering if the was any way to determine the state of the caps lock key, on or off. Of course I can capture the key events and see whether the caps lock is pressed, but that does not...
4
by: Peter D | last post by:
I have a second hand bar code reader (keyboard wedge) en i can read the bar codes but after every scan he turns my caps lock on. (GRRRRRR). I search a code to turn my caps lock off or can anyone...
20
by: Malcolm | last post by:
Use all lower case for ansi c functions, and Capitalise For Platform-Specific. If you call something with caps, then your function name requires caps itself.
3
by: Mike L | last post by:
How do I turn Caps Lock on, when my form opens?
7
by: John A Grandy | last post by:
does anyone know of an intrinsic .NET function , or font , or other mechanism , to do "proper-case all-caps" ... ? so, for a name like "Arnold Schwarzenegger" ... .... I want it entirely in...
1
by: charlies224 | last post by:
Hi, I am writting a software that requires me to make sure the Num Lock is always on and Caps Lock is always off. First, I know how to detect if Num Lock or Caps Lock is on or off (if...
8
by: sengmca | last post by:
hi friends, this is senny, here i have to solve my pbm thrugh ur kind suggestion.In my project ,i have to restrict the user to use "CAPS KEY" like when we go to login if caps pressed the msbbox is...
2
by: Fred's | last post by:
Hi Folks, I've been trying to figure out how can I see the text in caps in my report, but til now, nothing works. Does anyone knows how can I makes the text in caps in my report? Your...
9
by: trondhuso | last post by:
Hi, I have a solution that - at time of writing - has to use tables to render a list of database-results. My challenge though is that we have used iframes and such to render the different lists...
18
by: DanicaDear | last post by:
I want to use all caps in a database. I desire to show all caps AS YOU TYPE regardless of how the keyboard/caps lock is set. I tried to format my form field with an on-click event…and this is the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.