积极答复者
如果要即时控制NumLock灯切换,如何用VB.net代码实现?

问题
答案
-
如果要即时控制NumLock灯切换,如何用VB.net代码实现?
SendKeys("{NUMLOCK}")好像不起作用?
编程是永无止境的,向大家学习
我们可以用以下代码来切换NumLock。
Dim WshShell As Object = CreateObject("WScript.Shell") WshShell.SendKeys("{NUMLOCK}")
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
多谢您的回答,但是这段代码跟在vbnet中的
SendKeys("{NUMLOCK}")
一样没有起作用,试验了一下CAPSLOCK都可以起作用,不知道是不是Win8系统的原因?
另外,如果VB.net本身能实现,就没有必要再用VBS来做了,感觉回到了VB6.0的样子。
编程是永无止境的,向大家学习
实际上它确实可以控制CAPSLOCK, 只是不能够反馈到键盘的指示灯上。
你可以自己在win8上测试下, 系统自带的屏幕键盘,我测试的结果是它也不能控制键盘灯的切换。
另外,当前板块仅讨论有关vb.net的问题 有关vbs 和 vb6 的问题不在当前板块的支持范围。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Youjun TangModerator 2015年2月24日 3:15
-
查找了下, 你可以尝试下这里用到的win32的API http://support.microsoft.com/kb/177674/zh-cn。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
我测试了下 跟vb.net 稍许有些差别。
相关API声明:
Private Structure OSVERSIONINFO Dim dwOSVersionInfoSize As Integer Dim dwMajorVersion As Integer Dim dwMinorVersion As Integer Dim dwBuildNumber As Integer Dim dwPlatformId As Integer <VBFixedString(128), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=128)> Public szCSDVersion As String ' Maintenance string for PSS usage End Structure Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Integer Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer) Private Declare Function GetKeyboardState Lib "user32" (ByRef pbKeyState As Byte) As Integer Private Declare Function SetKeyboardState Lib "user32" (ByRef lppbKeyState As Byte) As Integer 'const Const VK_NUMLOCK As Short = &H90S Const VK_SCROLL As Short = &H91S Const VK_CAPITAL As Short = &H14S Const KEYEVENTF_EXTENDEDKEY As Short = &H1S Const KEYEVENTF_KEYUP As Short = &H2S Const VER_PLATFORM_WIN32_NT As Short = 2 Const VER_PLATFORM_WIN32_WINDOWS As Short = 1
具体实现:
Private Sub cmdCapsLock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCapsLock.Click Dim o As OSVERSIONINFO Dim CapsLockState As Boolean o.dwOSVersionInfoSize = Len(o) GetVersionEx(o) Dim keys(255) As Byte GetKeyboardState(keys(0)) 'CAPSLOCK CapsLockState = keys(VK_CAPITAL) 'check CAPSLOCK state If CapsLockState <> True Then 'if disabled then enable it If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then '=== Win95/98 keys(VK_CAPITAL) = 1 SetKeyboardState(keys(0)) ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then '=== WinNT 'Key Press keybd_event(VK_CAPITAL, &H45S, KEYEVENTF_EXTENDEDKEY Or 0, 0) 'Key Release keybd_event(VK_CAPITAL, &H45S, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) End If Else 'se estiver ativado -> if enabled then disable it If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then '=== Win95/98 keys(VK_CAPITAL) = 0 SetKeyboardState(keys(0)) ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then '=== WinNT 'Key Press keybd_event(VK_CAPITAL, &H45S, KEYEVENTF_EXTENDEDKEY Or 0, 0) 'Key Release keybd_event(VK_CAPITAL, &H45S, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) End If End If End Sub
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Youjun TangModerator 2015年2月24日 3:15
全部回复
-
如果要即时控制NumLock灯切换,如何用VB.net代码实现?
SendKeys("{NUMLOCK}")好像不起作用?
编程是永无止境的,向大家学习
我们可以用以下代码来切换NumLock。
Dim WshShell As Object = CreateObject("WScript.Shell") WshShell.SendKeys("{NUMLOCK}")
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
如果要即时控制NumLock灯切换,如何用VB.net代码实现?
SendKeys("{NUMLOCK}")好像不起作用?
编程是永无止境的,向大家学习
我们可以用以下代码来切换NumLock。
Dim WshShell As Object = CreateObject("WScript.Shell") WshShell.SendKeys("{NUMLOCK}")
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
多谢您的回答,但是这段代码跟在vbnet中的
SendKeys("{NUMLOCK}")
一样没有起作用,试验了一下CAPSLOCK都可以起作用,不知道是不是Win8系统的原因?
另外,如果VB.net本身能实现,就没有必要再用VBS来做了,感觉回到了VB6.0的样子。
编程是永无止境的,向大家学习
-
如果要即时控制NumLock灯切换,如何用VB.net代码实现?
SendKeys("{NUMLOCK}")好像不起作用?
编程是永无止境的,向大家学习
我们可以用以下代码来切换NumLock。
Dim WshShell As Object = CreateObject("WScript.Shell") WshShell.SendKeys("{NUMLOCK}")
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
多谢您的回答,但是这段代码跟在vbnet中的
SendKeys("{NUMLOCK}")
一样没有起作用,试验了一下CAPSLOCK都可以起作用,不知道是不是Win8系统的原因?
另外,如果VB.net本身能实现,就没有必要再用VBS来做了,感觉回到了VB6.0的样子。
编程是永无止境的,向大家学习
实际上它确实可以控制CAPSLOCK, 只是不能够反馈到键盘的指示灯上。
你可以自己在win8上测试下, 系统自带的屏幕键盘,我测试的结果是它也不能控制键盘灯的切换。
另外,当前板块仅讨论有关vb.net的问题 有关vbs 和 vb6 的问题不在当前板块的支持范围。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Youjun TangModerator 2015年2月24日 3:15
-
查找了下, 你可以尝试下这里用到的win32的API http://support.microsoft.com/kb/177674/zh-cn。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
- 已编辑 Carl CaiModerator 2015年2月19日 5:57 改成中文链接
-
查找了下, 你可以尝试下这里用到的win32的API http://support.microsoft.com/kb/177674/zh-cn。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
我测试了下 跟vb.net 稍许有些差别。
相关API声明:
Private Structure OSVERSIONINFO Dim dwOSVersionInfoSize As Integer Dim dwMajorVersion As Integer Dim dwMinorVersion As Integer Dim dwBuildNumber As Integer Dim dwPlatformId As Integer <VBFixedString(128), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=128)> Public szCSDVersion As String ' Maintenance string for PSS usage End Structure Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Integer Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer) Private Declare Function GetKeyboardState Lib "user32" (ByRef pbKeyState As Byte) As Integer Private Declare Function SetKeyboardState Lib "user32" (ByRef lppbKeyState As Byte) As Integer 'const Const VK_NUMLOCK As Short = &H90S Const VK_SCROLL As Short = &H91S Const VK_CAPITAL As Short = &H14S Const KEYEVENTF_EXTENDEDKEY As Short = &H1S Const KEYEVENTF_KEYUP As Short = &H2S Const VER_PLATFORM_WIN32_NT As Short = 2 Const VER_PLATFORM_WIN32_WINDOWS As Short = 1
具体实现:
Private Sub cmdCapsLock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCapsLock.Click Dim o As OSVERSIONINFO Dim CapsLockState As Boolean o.dwOSVersionInfoSize = Len(o) GetVersionEx(o) Dim keys(255) As Byte GetKeyboardState(keys(0)) 'CAPSLOCK CapsLockState = keys(VK_CAPITAL) 'check CAPSLOCK state If CapsLockState <> True Then 'if disabled then enable it If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then '=== Win95/98 keys(VK_CAPITAL) = 1 SetKeyboardState(keys(0)) ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then '=== WinNT 'Key Press keybd_event(VK_CAPITAL, &H45S, KEYEVENTF_EXTENDEDKEY Or 0, 0) 'Key Release keybd_event(VK_CAPITAL, &H45S, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) End If Else 'se estiver ativado -> if enabled then disable it If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then '=== Win95/98 keys(VK_CAPITAL) = 0 SetKeyboardState(keys(0)) ElseIf o.dwPlatformId = VER_PLATFORM_WIN32_NT Then '=== WinNT 'Key Press keybd_event(VK_CAPITAL, &H45S, KEYEVENTF_EXTENDEDKEY Or 0, 0) 'Key Release keybd_event(VK_CAPITAL, &H45S, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) End If End If End Sub
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Youjun TangModerator 2015年2月24日 3:15