By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,593 Members | 2,006 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,593 IT Pros & Developers. It's quick & easy.

how on the caps key

chandru8
100+
P: 145
Hi everyone .
Can anyone help me how on the caps key through coding?
Nov 27 '07 #1
Share this Question
Share on Google+
3 Replies


9815402440
100+
P: 180
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

Expert 5K+
P: 8,434
Thanks, Manpreet. But it might help if chandru8 could tell us what the actual question is.
Nov 27 '07 #3

chandru8
100+
P: 145
Thanks, Manpreet
thanks for your kindly help
Nov 27 '07 #4

Post your reply

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