Tastendruck simulieren

  • VB.NET

Es gibt 29 Antworten in diesem Thema. Der letzte Beitrag () ist von meikmenzel.

    Tastendruck simulieren

    Ich bräuchte mal hilfe beim Simulieren von der Capslock, die Taste über Shift(Hab den namen vergessen...) und der Scroll taste.
    Also wenn ich jetzt ein button drücke soll man dann die jeweilige funktion an bzw. aus gehen.

    Vielen Dank :thumbsup:
    System.Windows.Forms.SendKeys.SendWait("{TAB}")

    Liste von Sendkeys:
    Spoiler anzeigen

    {!} <-> !
    {#} <-> #
    {+} <-> +
    {^} <-> ^
    {{} <-> {
    {}} <-> }
    {SPACE} <-> SPACE
    {ENTER} <-> ENTER key on the main keyboard
    {ALT} <-> ALT
    {BACKSPACE} or {BS} <-> BACKSPACE
    {DELETE} or {DEL} <-> DELETE
    {UP} <-> Up arrow
    {DOWN} <-> Down arrow
    {LEFT} <-> Left arrow
    {RIGHT} <-> Right arrow
    {HOME} <-> HOME
    {END} <-> END
    {ESCAPE} or {ESC} <-> ESCAPE
    {INSERT} or {INS} <-> INS
    {PGUP} <-> PGUP
    {PGDN} <-> PGDN
    {F1} - {F12} <-> Function keys
    {TAB} <-> TAB
    {PRINTSCREEN} <-> PRINTSCR
    {LWIN} <-> Left Windows key
    {RWIN} <-> Right Windows key
    {NUMLOCK} <-> NUMLOCK
    {CAPSLOCK} <-> CAPSLOCK
    {SCROLLLOCK} <-> SCROLLLOCK
    {BREAK} <-> for Ctrl+Break processing
    {PAUSE} <-> PAUSE
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    Ich habs jetzt so gemacht aber es funktioniert nicht:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3. System.Windows.Forms.SendKeys.SendWait("{CAPSLOCK}")
    4. End Sub
    5. End Class


    :cursing:
    Ich vermute jetzt einfach mal das du auf in einem Anderen Element oder Prozess eine Funktione aufrufen möchtest.

    Daher musst du wahrscheinlich dem Element noch den Fokus geben bzw. dem Prozess den Fokus geben
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    Wer soll die Taste senden, wer soll die Taste empfangen?
    Welches Fenster hat definitiv den Fokus / nicht den Fokus?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Ich hab es mal über die Win-API versucht.
    So sollte es gehen:

    VB.NET-Quellcode

    1. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
    2. Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As Integer
    3. Private Const KEYEVENTF_KEYUP As Short = &H2S
    4. Sub SetCaps(ByVal Status As Boolean)
    5. keybd_event(System.Windows.Forms.Keys.CapsLock, 0, 0, 0)
    6. keybd_event(System.Windows.Forms.Keys.CapsLock, 0, KEYEVENTF_KEYUP, 0)
    7. End Sub
    8. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    9. If CBool(GetKeyState(System.Windows.Forms.Keys.CapsLock)) = True Then
    10. SetCaps(False)
    11. Else
    12. SetCaps(True)
    13. End If
    14. End Sub
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    So (der code funktioniert :D vielen dank!!!) nun wollte ich noch die num taste drücken:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
    3. Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As Integer
    4. Private Const KEYEVENTF_KEYUP As Short = &H2S
    5. Sub SetCaps(ByVal Status As Boolean)
    6. keybd_event(System.Windows.Forms.Keys.CapsLock, 0, 0, 0)
    7. keybd_event(System.Windows.Forms.Keys.CapsLock, 0, KEYEVENTF_KEYUP, 0)
    8. End Sub
    9. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    10. If CBool(GetKeyState(System.Windows.Forms.Keys.CapsLock)) = True Then
    11. SetCaps(False)
    12. Else
    13. SetCaps(True)
    14. End If
    15. End Sub
    16. Sub Setnum(ByVal Status As Boolean)
    17. keybd_event(System.Windows.Forms.Keys.NumLock, 0, 0, 0)
    18. keybd_event(System.Windows.Forms.Keys.NumLock, 0, KEYEVENTF_KEYUP, 0)
    19. End Sub
    20. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    21. If CBool(GetKeyState(System.Windows.Forms.Keys.NumLock)) = True Then
    22. Setnum(False)
    23. Else
    24. Setnum(True)
    25. End If
    26. End Sub
    27. End Class


    Aber wenn ich button 1 drücke werden num und capslock gedrückt und wenn ich button 2 drücke passiert nichts... Wo liegt der fehler?


    Sorry habe denn fehler gefunden... Habe
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click statt
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click geschrieben
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ...
    End Sub

    Benutze Button2.click im Handles sonst wird das nix


    _________


    Edit:
    OK warst schneller :)
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."