Sie sind nicht verbunden. Loggen Sie sich ein oder registrieren Sie sich

Anzeige Leuchten auf der Tastatur steuern

Nach unten  Nachricht [Seite 1 von 1]

1 Anzeige Leuchten auf der Tastatur steuern am Mi Nov 17, 2010 8:57 pm

Niklas Admin

avatar
Admin
Hallo,
gibt es eine Möglichkeit in Visual Basic die Num-, Caps- und Rollen/Scroll-Lampen an bzw. aus zu schalten? Über Sendkeys habe ich es schon probiert, es ging aber nicht. Es dient nur zu Demonstrationszwecken und hat kaum einen Sinn.


_________________
Mit freundlichen Grüßen
Niklas
http://vbs-linux.dbzworld.org

2 Re: Anzeige Leuchten auf der Tastatur steuern am Fr Nov 19, 2010 11:12 pm

Trojan

avatar
Welche VB-Version solls denn sein?

Niklas Admin

avatar
Admin
Es soll für Visual Basic 2010 sein, aber ich habe das Problem bereits gelöst. Hier ist der Code:
Code:
Public Class Form1
    Private Declare Function GetKeyboardState Lib "user32" _
        (ByVal pbKeyState As Byte) As Long

    Private Declare Function GetKeyState Lib "user32" _
          (ByVal nVirtKey As Long) As Integer

    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 SetKeyboardState Lib "user32" _
          (ByVal lppbKeyState As Byte) As Long

    Private Const KEYEVENTF_EXTENDEDKEY = &H1
    Private Const KEYEVENTF_KEYUP = &H2


    Private Const VK_CAPS = &H14
    Private Const VK_NUM = &H90
    Private Const VK_SCROLL = &H91

    Dim keys(0 To 255) As Byte

    Dim stufe As Integer

    Private oSv As OperatingSystem

    Private Function KeyStatus(ByVal Taste As Integer) As Boolean
        oSv = Environment.OSVersion

        If My.Computer.Keyboard.NumLock = True Then
            keys(VK_NUM) = 1
        Else
            keys(VK_NUM) = 0
        End If
        If My.Computer.Keyboard.CapsLock = True Then
            keys(VK_CAPS) = 1
        Else
            keys(VK_CAPS) = 0
        End If
        If My.Computer.Keyboard.ScrollLock = True Then
            keys(VK_SCROLL) = 1
        Else
            keys(VK_SCROLL) = 0
        End If

        Return keys(Taste)

    End Function

    Private Sub Switch(ByVal Taste As Integer, ByVal AnAus As Boolean)
        If (KeyStatus(Taste) <> AnAus) Then
            If (oSv.Platform = PlatformID.Win32Windows) Then
                keys(Taste) = 1
                SetKeyboardState(keys(0))
            ElseIf (oSv.Platform = PlatformID.Win32NT) Then
                keybd_event(Taste, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)
                keybd_event(Taste, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
            End If
        End If

    End Sub

    Private Sub traspeed_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles traspeed.ValueChanged
        restart()
    End Sub

    Sub restart()
        Timer1.Interval = traspeed.Value * 10
        Switch(VK_CAPS, False)
        Switch(VK_NUM, False)
        Switch(VK_SCROLL, False)
    End Sub

    Private Sub cmdstart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdstart.Click
        Timer1.Start()
        restart()
    End Sub

    Private Sub cmdstop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdstop.Click
        Timer1.Stop()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If stufe = 1 Then
            Switch(VK_CAPS, True)
            Switch(VK_NUM, False)
            Switch(VK_SCROLL, False)
        ElseIf stufe = 2 Then
            Switch(VK_CAPS, False)
            Switch(VK_NUM, False)
            Switch(VK_SCROLL, True)
        ElseIf stufe = 3 Then
            Switch(VK_CAPS, False)
            Switch(VK_NUM, True)
            Switch(VK_SCROLL, False)
        End If
        If stufe = 3 Then
            stufe = 0
        End If
        stufe = stufe + 1
    End Sub
End Class


_________________
Mit freundlichen Grüßen
Niklas
http://vbs-linux.dbzworld.org

Gesponserte Inhalte


Nach oben  Nachricht [Seite 1 von 1]

Befugnisse in diesem Forum
Sie können in diesem Forum nicht antworten