ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   switch the "scroll" led with vba (https://www.excelbanter.com/excel-programming/402078-switch-scroll-led-vba.html)

MicrosoftNews

switch the "scroll" led with vba
 
Hi,

I want to switch the "scroll" led with vba on and of with different buttons
....

I want to switch on and off the scroll led with the following code
-------------------------------------------------------------------------------------
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Const VK_OEM_SCROLL = &H91
Private Const KEYEVENTF_KEYUP = &H2
Declare Function GetKeyState Lib "user32.dll" ( _
ByVal nVirtKey As Long) As Integer

Sub SCROLL_aktiv() 'SCROLL-Lock aktivieren (falls deaktiviert)
If Not (GetKeyState(vbKeyOEM_SCROLL) = 1) Then
keybd_event VK_OEM_SCROLL, 1, 0, 0
keybd_event VK_OEM_SCROLL, 1, KEYEVENTF_KEYUP, 0
End If
End Sub

Sub SCROLL_inaktiv() ' SCROLL-Lock deaktivieren (falls aktiviert)
If (GetKeyState(vbKeyOEM_SCROLL) = 1) Then
keybd_event VK_OEM_SCROLL, 1, 0, 0
keybd_event VK_OEM_SCROLL, 1, KEYEVENTF_KEYUP, 0
End If
End Sub
----------------------------------------------------------------------------------------

with the scroll_aktiv procedure i can toggle between on and off. but it
should only switch on the led. with scroll_inaktiv i can't switch of the
led - and i don't know why

the following procedure for the num lock led works fine
------------------------------------------------------------------------------
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Const VK_NUMLOCK = &H90
Private Const KEYEVENTF_KEYUP = &H2
Declare Function GetKeyState Lib "user32.dll" ( _
ByVal nVirtKey As Long) As Integer

Sub NUM_TOGGLE()
' NUM-Lock drücken
' Zunächst niederdrücken und dann wieder loslassen
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End Sub

Sub NUM_aktiv() 'NUM-Lock aktivieren (falls deaktiviert)
If Not (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
End Sub

Sub NUM_inaktiv() ' NUM-Lock deaktivieren (falls aktiviert)
If (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
End Sub
------------------------------------------------------------------------------------
thanks for any help ..
achim



Peter T

switch the "scroll" led with vba
 
In W9x can do simply this (API's not posted)

Const VK_SCROLL As Long = &H91
Dim keys(0 To 255) As Byte
GetKeyboardState keys(0)
keys(VK_SCROLL) = 1
SetKeyboardState keys(0)

It seems in later versions need to do a bit more to switch the led, try
this -

http://support.microsoft.com/kb/177674

The example is aimed at VB(4/5/6) users, paste all incl Command1_Click into
a normal module and run (and perhaps rename) "Command1_Click".

Regards,
Peter T

"MicrosoftNews" wrote in message
...
Hi,

I want to switch the "scroll" led with vba on and of with different

buttons
...

I want to switch on and off the scroll led with the following code
--------------------------------------------------------------------------

-----------
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Const VK_OEM_SCROLL = &H91
Private Const KEYEVENTF_KEYUP = &H2
Declare Function GetKeyState Lib "user32.dll" ( _
ByVal nVirtKey As Long) As Integer

Sub SCROLL_aktiv() 'SCROLL-Lock aktivieren (falls deaktiviert)
If Not (GetKeyState(vbKeyOEM_SCROLL) = 1) Then
keybd_event VK_OEM_SCROLL, 1, 0, 0
keybd_event VK_OEM_SCROLL, 1, KEYEVENTF_KEYUP, 0
End If
End Sub

Sub SCROLL_inaktiv() ' SCROLL-Lock deaktivieren (falls aktiviert)
If (GetKeyState(vbKeyOEM_SCROLL) = 1) Then
keybd_event VK_OEM_SCROLL, 1, 0, 0
keybd_event VK_OEM_SCROLL, 1, KEYEVENTF_KEYUP, 0
End If
End Sub
--------------------------------------------------------------------------

--------------

with the scroll_aktiv procedure i can toggle between on and off. but it
should only switch on the led. with scroll_inaktiv i can't switch of the
led - and i don't know why

the following procedure for the num lock led works fine
--------------------------------------------------------------------------

----
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Const VK_NUMLOCK = &H90
Private Const KEYEVENTF_KEYUP = &H2
Declare Function GetKeyState Lib "user32.dll" ( _
ByVal nVirtKey As Long) As Integer

Sub NUM_TOGGLE()
' NUM-Lock drücken
' Zunächst niederdrücken und dann wieder loslassen
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End Sub

Sub NUM_aktiv() 'NUM-Lock aktivieren (falls deaktiviert)
If Not (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
End Sub

Sub NUM_inaktiv() ' NUM-Lock deaktivieren (falls aktiviert)
If (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
End Sub
--------------------------------------------------------------------------

----------
thanks for any help ..
achim






All times are GMT +1. The time now is 06:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com