Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: КАК заставить XP мигать индикаторы на клаве [N... Добавлено: 18.03.04 23:15  

Автор вопроса:  MasterYan | Web-сайт: vc-studio.org/ | ICQ: 167425994 

КАК заставить XP мигать индикаторы на клаве [NumLock] [CapsLock]...

Лучше всего если код будет пахать под любую винду.

Ответить

  Ответы Всего ответов: 2  

Номер ответа: 1
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #1
Добавлено: 19.03.04 00:10

' Вот, как ни удивительно у меня как раз завалялся примерчик мигания клавишами ;)
' И что самое интересное, под любую винду :)

 


'******************************************************************
' Author : Lior Ben-Arie
'
' This code shows how to synconize and function with Scroll Lock,
' Num Lock and Caps Lock Keys.
'
' Most of the code is taken from Microsoft MSDN...
'
' Enjoy ...
'******************************************************************

 

Option Explicit

 

' Declare Type for API call:
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type

 

' Constant declarations:
Const VK_NUMLOCK = &H90
Const VK_SCROLL = &H91
Const VK_CAPITAL = &H14
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Const VER_PLATFORM_WIN32_NT = 2
Const VER_PLATFORM_WIN32_WINDOWS = 1
Const KEY_COLOR_ON = vbGreen
Const KEY_COLOR_OFF = &H8000000F

 

' API declarations:
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long

 

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)

 

Private Declare Function GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long

 

Private Declare Function SetKeyboardState Lib "user32" _
(lppbKeyState As Byte) As Long

 

Private OSInfo As OSVERSIONINFO
Private keys(0 To 255) As Byte

 

Private Sub cmdCaps_Click()
' Call to Sub ChangeKeyStatus in order to change the actual status of the key
Call ChangeKeyStatus(VK_CAPITAL, cmdCaps.BackColor = KEY_COLOR_OFF)
' Indicate Key status by it's color (Only for Win9x,
' In WINNT color status changes in Form_KeyDown)
If OSInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then '--> Win9x
cmdCaps.BackColor = IIf(cmdCaps.BackColor = KEY_COLOR_OFF, KEY_COLOR_ON, KEY_COLOR_OFF)
End If
End Sub

 

Private Sub cmdNum_Click()
' Call to Sub ChangeKeyStatus in order to change the actual status of the key
Call ChangeKeyStatus(VK_NUMLOCK, cmdNum.BackColor = KEY_COLOR_OFF)
' Indicate Key status by it's color (Only for Win9x,
' In WINNT color status changes in Form_KeyDown)
If OSInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then '--> Win9x
cmdNum.BackColor = IIf(cmdNum.BackColor = KEY_COLOR_OFF, KEY_COLOR_ON, KEY_COLOR_OFF)
End If
End Sub

 

Private Sub cmdScroll_Click()
' Call to Sub ChangeKeyStatus in order to change the actual status of the key
Call ChangeKeyStatus(VK_SCROLL, cmdScroll.BackColor = KEY_COLOR_OFF)
' Indicate Key status by it's color (Only for Win9x,
' In WINNT color status changes in Form_KeyDown)
If OSInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then '--> Win9x
cmdScroll.BackColor = IIf(cmdScroll.BackColor = KEY_COLOR_OFF, KEY_COLOR_ON, KEY_COLOR_OFF)
End If
End Sub

 

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
' When pressing the Key on the keyboard the button color will change accordingly
Select Case KeyCode
Case VK_CAPITAL: cmdCaps.BackColor = IIf(cmdCaps.BackColor = KEY_COLOR_OFF, KEY_COLOR_ON, KEY_COLOR_OFF)
Case VK_SCROLL: cmdScroll.BackColor = IIf(cmdScroll.BackColor = KEY_COLOR_OFF, KEY_COLOR_ON, KEY_COLOR_OFF)
Case VK_NUMLOCK: cmdNum.BackColor = IIf(cmdNum.BackColor = KEY_COLOR_OFF, KEY_COLOR_ON, KEY_COLOR_OFF)
End Select
End Sub

 

Private Sub Form_Load()

' Get operating system information
OSInfo.dwOSVersionInfoSize = Len(OSInfo)
GetVersionEx OSInfo

' Get keyboard status into keys array
GetKeyboardState keys(0)

' Indicate Key status by it's color
cmdNum.BackColor = IIf(keys(VK_NUMLOCK), KEY_COLOR_ON, KEY_COLOR_OFF)
cmdCaps.BackColor = IIf(keys(VK_CAPITAL), KEY_COLOR_ON, KEY_COLOR_OFF)
cmdScroll.BackColor = IIf(keys(VK_SCROLL), KEY_COLOR_ON, KEY_COLOR_OFF)

End Sub

 

Private Sub ChangeKeyStatus(ByVal lngKey As Long, ByVal bOn As Boolean)

' It's quite clear what this sub does...

If OSInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then '--> Win9x
keys(lngKey) = IIf(bOn, 1, 0)
SetKeyboardState keys(0)
ElseIf OSInfo.dwPlatformId = VER_PLATFORM_WIN32_NT Then '--> WinNT
'Simulate Key Press
keybd_event lngKey, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
'Simulate Key Release
keybd_event lngKey, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
End If

End Sub

Ответить

Номер ответа: 2
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #2
Добавлено: 19.03.04 00:13

Да, забыл сказать, что на форме было 3 кнопки:

cmdNum

cmdCaps

cmdScroll

И свойство у всех - Graphical...

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам