GetASyncKeyState Tastenkombination

  • VB.NET

Es gibt 11 Antworten in diesem Thema. Der letzte Beitrag () ist von SystemUnknow.

    GetASyncKeyState Tastenkombination

    Hey,
    Wie kann ich bei getasynckeystate tastenkombinationen festlegen?

    VB.NET-Quellcode

    1. Private Declare Function GetAsyncKeyState Lib "USER32" (ByVal vKey As Long) As Integer
    2. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    3. If GetAsyncKeyState(Keys.Control) And GetAsyncKeyState(Keys.Space) Then
    4. Me.Show()
    5. Panel1.Show()
    6. End If
    7. End Sub

    So will es nicht, was mache ich falsch?

    Greetz
    Moderatorin: "Apropo ritzen.." Shin Chan: "hoho sie hat Po ritze gesagt"
    "saying to buy a mac because your anti-virus expired is like saying you're out of condoms so you're just going to go fuck dudes"
    "Wie auch in anderen Threads kann ich leider nichts bieten außer vielleicht spaß beim Skypen aber mehr leider auch nicht." - Sind kinder pornos nicht verboten?
    Versuchs mal mit

    VB.NET-Quellcode

    1. Private Declare Function GetAsyncKeyState Lib "USER32" (ByVal vKey As Keys) As Short
    2. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    3. If (GetAsyncKeyState(Keys.Control Or Keys.Space) And &H8000S) = &H8000S Then
    4. Me.Show()
    5. Panel1.Show()
    6. End If
    7. End Sub


    Für Key-Events solltest du aber einen Hook verwenden, wenn das der Zweck ist...

    Gruß
    ~blaze~
    Hey,
    Hab grad gemerkt das controlkey, strg ist und nicht control, aber so funktionierts auch ned:

    VB.NET-Quellcode

    1. Private Declare Function GetAsyncKeyState Lib "USER32" (ByVal vKey As Keys) As Short
    2. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    3. If (GetAsyncKeyState(Keys.ControlKey Or Keys.Space) And &H8000S) = &H8000S Then
    4. Me.Show()
    5. Panel1.Show()
    6. End If
    7. End Sub

    Greetz
    Moderatorin: "Apropo ritzen.." Shin Chan: "hoho sie hat Po ritze gesagt"
    "saying to buy a mac because your anti-virus expired is like saying you're out of condoms so you're just going to go fuck dudes"
    "Wie auch in anderen Threads kann ich leider nichts bieten außer vielleicht spaß beim Skypen aber mehr leider auch nicht." - Sind kinder pornos nicht verboten?
    Das scheint mit den Flags nicht zu funktionieren. Dann halt über die Variante mit ModifierKeys:

    VB.NET-Quellcode

    1. <Runtime.InteropServices.Import("user32.dll")> _
    2. Private Shared Function GetAsyncKeyState(ByVal vKey As Keys) As Short
    3. End Function
    4. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    5. If (GetAsyncKeyState(Keys.Space) And &H8000S) = &H8000S AndAlso (Control.ModifierKeys = Keys.Control) Then
    6. Me.Show()
    7. Panel1.Show()
    8. End If
    9. End Sub


    Gruß
    ~blaze~
    Hey,
    Geht leider immernoch nicht.. :S

    Greetz
    Moderatorin: "Apropo ritzen.." Shin Chan: "hoho sie hat Po ritze gesagt"
    "saying to buy a mac because your anti-virus expired is like saying you're out of condoms so you're just going to go fuck dudes"
    "Wie auch in anderen Threads kann ich leider nichts bieten außer vielleicht spaß beim Skypen aber mehr leider auch nicht." - Sind kinder pornos nicht verboten?
    Hey,
    Ich drücke Strg + Space, und nichts passiert?

    Greetz
    Moderatorin: "Apropo ritzen.." Shin Chan: "hoho sie hat Po ritze gesagt"
    "saying to buy a mac because your anti-virus expired is like saying you're out of condoms so you're just going to go fuck dudes"
    "Wie auch in anderen Threads kann ich leider nichts bieten außer vielleicht spaß beim Skypen aber mehr leider auch nicht." - Sind kinder pornos nicht verboten?
    Bei mir funktioniert das so:

    VB.NET-Quellcode

    1. Dim b1 As Boolean = ((GetAsyncKeyState(Keys.Space) And &H8000) <> 0)
    2. Dim b2 As Boolean = ((GetAsyncKeyState(Keys.Control) And &H8000) <> 0)
    3. If (b1 AndAlso b2) Then
    4. ' beide Tasten gedrückt
    5. End If
    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!
    Ist halt fraglich, was er will:
    msdn.microsoft.com/en-us/libra…s646293%28v=vs.85%29.aspx
    If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState.


    Aber wie gesagt: Eigentlich wäre ein Hook in der Situation viel besser. msdn.microsoft.com/en-us/library/ms644959%28VS.85%29.aspx

    Gruß
    ~blaze~
    Hey,
    Der Code von rod hat bei mir geklappt, danke an beide.

    Greetz
    Moderatorin: "Apropo ritzen.." Shin Chan: "hoho sie hat Po ritze gesagt"
    "saying to buy a mac because your anti-virus expired is like saying you're out of condoms so you're just going to go fuck dudes"
    "Wie auch in anderen Threads kann ich leider nichts bieten außer vielleicht spaß beim Skypen aber mehr leider auch nicht." - Sind kinder pornos nicht verboten?