IfPressed

    • Offizieller Beitrag

    Hi,

    [autoit]

    $dll = DllOpen("user32.dll")
    While _IsPressedMod($dll); clear buffer
    WEnd

    [/autoit][autoit][/autoit][autoit]

    While 1
    Sleep(250)
    $typed = _IsPressedMod($dll)
    If $typed Then ExitLoop
    WEnd
    DllClose($dll)

    [/autoit][autoit][/autoit][autoit]

    MsgBox(0,'',$typed & @LF)

    [/autoit][autoit][/autoit][autoit]

    ; http://msdn.microsoft.com/library/default....ualKeyCodes.asp
    Func _IsPressedMod($dll = "user32.dll")
    Local $aR, $bRv, $hexKey, $i
    For $i = 1 To 256
    $hexKey = '0x' & Hex($i, 2)
    $aR = DllCall($dll, "int", "GetAsyncKeyState", "int", $hexKey)
    If $aR[0] <> 0 Then Return Hex($i,2)
    Next
    Return 0
    EndFunc ;==>_IsPressedMod

    [/autoit]

    So long,

    Mega

  • Hi,

    dieser Funktion (GetAsyncKeyState) wird ein "virtual key code" übergeben. Für sprachspezifische Sonderzeichen ist so ein "code" nicht vorhanden.

    Eine ausführliche erklärung findest Du hier

    • Offizieller Beitrag

    Hallo!

    Folgende codes sollten funktionieren!

    Code
    ä = 0xDE
    ö = 0xC0
    ü = 0xBA
    • Offizieller Beitrag

    HI bernd,

    hast du das mal getestet?

    Spoiler anzeigen
    [autoit]

    $dll = DllOpen("user32.dll")

    [/autoit] [autoit][/autoit] [autoit]

    Global $keys[3] = ['DE', 'C0', 'BA']
    Global $print[3] = ['ä', 'ö', 'ü']

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    For $i = 0 To UBound($keys) - 1
    If _IsPressed($keys[$i], $dll) Then
    MsgBox(0, "_IsPressed", $print[$i] & " Key Pressed")
    ExitLoop
    EndIf
    Next
    Sleep(5)
    WEnd
    DllClose($dll)

    [/autoit] [autoit][/autoit] [autoit]

    Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    ; $hexKey must be the value of one of the keys.
    ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
    EndFunc ;==>_IsPressed

    [/autoit]

    So long,

    Mega

    • Offizieller Beitrag

    Hallo Mega,

    warum geht es nicht?

    Bei mir (z.Z. auf W2K) läuft's!

    • Offizieller Beitrag

    Ich hab's eben noch mal auf XP Pro SP2 getestet -> läuft ohne Probleme!

  • Bei mir klappt es - Danke

    Welche Codes sind das denn ?
    Ich hatte schon mal in der Hilfe bei den erweiteretn Codes Gekuckt und bin dann auf andere Werte gestoßen

    Wennes interssiert hier der Betreffende Codeabschnitt in meinem Script.
    Es geht darum bei einer Listview Aanzeige mit entsprechendem tastendruck zu einem Eintrag mit dem Buchstaben zu springen.
    Damit das wunschgemäß funktioniert muß man ein bischen mit dem Sleep in der Function load Picture spielen, da sonst das falsche Bild geladen wird.


    Spoiler anzeigen
    [autoit]


    #include <file.au3>
    #include <Array.au3>
    #include <GUIConstants.au3>
    #include <GuiListview.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Opt("TrayIconDebug", 1) ; zeigt am trayicon welchen Befehl das Script gerade Ausführt

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    dim $aRecords, $x, $listview, $name, $vorname, $tel, $mobil, $handy, $einfuegen, $Button1, $Button2, $uebernehmen, $nr, $x_n, $vorname_read, $name_read
    Global Const $THRESHOLD = Number(RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "DoubleClickSpeed"))
    Global $TIMER = TimerInit()
    $Picture_file = "\\fs5\edv_inst\!!LOGINDIR\logo\dhl_exel_supply_chain_c.gif"

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    if FileExists("C:\Centura3\publictelefon.csv") Then
    $file = "C:\Centura3\publictelefon.csv"
    ;~ $file = "C:\publictelefon.csv"
    FileCopy("C:\Centura3\publictelefon.csv","o:\telefon.csv",1)

    [/autoit] [autoit][/autoit] [autoit]

    Else
    $file = "o:\telefon.csv"

    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUICreate("Telefonlisten",750,330, 100,200,$WS_OVERLAPPEDWINDOW)
    $listview = GUICtrlCreateListView ("Name |Vorname |Telefon|Schnurlos|Handy ",10,10,520,230)
    $bearbeiten = GUICtrlCreateButton("Bearbeiten",10,250,80,20)
    $speichern = GUICtrlCreateButton("Datei speichern",100,250,80,20)
    $anlegen = GUICtrlCreateButton("Datensatz anlegen",190,250,100,20)
    $loeschen = GUICtrlCreateButton("Datensatz löschen",300,250,100,20)
    $array = GUICtrlCreateButton("Array anzeigen",410,250,100,20)
    $picture = GUICtrlCreatePic($Picture_file, 540,30,199,150)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;---Editfeld
    $name = GUICtrlCreateInput("Name",10, 280,80,20,-1 ,$WS_EX_CLIENTEDGE )
    $vorname = GUICtrlCreateInput("Vorname",100, 280,80,20,-1 ,$WS_EX_CLIENTEDGE )
    $tel = GUICtrlCreateInput("Telefon",190, 280,80,20,-1 ,$WS_EX_CLIENTEDGE )
    $mobil = GUICtrlCreateInput("Schnurlos",280, 280,80,20,-1 ,$WS_EX_CLIENTEDGE )
    $handy = GUICtrlCreateInput("Handy",370, 280,80,20,-1 ,$WS_EX_CLIENTEDGE )

    [/autoit] [autoit][/autoit] [autoit]

    $statuszeile = GUICtrlCreateLabel($file,10, 310,520,20,-1 )

    [/autoit] [autoit][/autoit] [autoit]

    $Button1 = GUICtrlCreateButton("übernehmen",460,280,70,20)
    GUICtrlSetState($Button1, $GUI_HIDE)
    ;~ $Button1 = GUICtrlCreateButton("",1460,280,70,20); Buttons sollen nicht sichtbar sein !

    [/autoit] [autoit][/autoit] [autoit]

    $Button2 = GUICtrlCreateButton("hinzufügen",460,280,70,20)
    GUICtrlSetState($Button2, $GUI_HIDE)
    ;~ $Button2 = GUICtrlCreateButton("",1460,280,70,20); Buttons sollen nicht sichtbar sein !

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;--- PROGRAMM ABLAUF

    [/autoit] [autoit][/autoit] [autoit]

    If Not _FileReadToArray($file, $aRecords) Then
    MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;~ _ArrayDisplay($aRecords,"")
    For $x = 1 to $aRecords[0]
    if $aRecords[$x] = "" Then
    _ArrayDelete($aRecords,$x)
    $help = $aRecords[0]
    $aRecords[0]= $help-1
    Else
    GUICtrlCreateListViewItem($aRecords[$x],$listview)
    EndIf
    Next
    ;Focus auf Listview setzen
    GUICtrlSetState($listview ,$GUI_FOCUS)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GuiGetMsg()

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("26") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("28") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("41") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("42") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("43") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("44") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("45") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("46") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("47") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("48") Then
    _load_picture()
    EndIf

    If _IsPressed("49") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("4A") Then
    _load_picture()
    EndIf

    If _IsPressed("4B") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("4C") Then
    _load_picture()
    EndIf

    If _IsPressed("4D") Then
    _load_picture()
    EndIf

    If _IsPressed("4E") Then
    _load_picture()
    EndIf

    If _IsPressed("4F") Then
    _load_picture()
    EndIf

    If _IsPressed("50") Then
    _load_picture()
    EndIf

    If _IsPressed("51") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("52") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("53") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("54") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("55") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("56") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("57") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("58") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("59") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("5A") Then
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("DE") Then ; Ä
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("C0") Then ; Ö
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If _IsPressed("BA") Then ; Ü
    _load_picture()
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Select
    Case $msg = $GUI_EVENT_CLOSE
    ExitLoop

    [/autoit] [autoit][/autoit] [autoit]

    Case $msg = $GUI_EVENT_PRIMARYDOWN
    _getLVItem_dbclick($listview)
    _load_picture()

    case $msg = $bearbeiten
    bearbeiten()

    case $msg = $speichern
    speichern()

    [/autoit] [autoit][/autoit] [autoit]

    Case $msg = $anlegen
    anlegen()

    [/autoit] [autoit][/autoit] [autoit]

    Case $msg = $Button1
    uebernehmen()

    [/autoit] [autoit][/autoit] [autoit]

    Case $msg = $Button2
    hinzufuegen()

    [/autoit] [autoit][/autoit] [autoit]

    Case $msg = $loeschen
    loeschen()

    [/autoit] [autoit][/autoit] [autoit]

    case $msg = $array
    _ArrayDisplay($aRecords, "Array Anzeigen")

    [/autoit] [autoit][/autoit] [autoit]

    Case Else
    ;~ ;;;
    EndSelect

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ;--- PROGRAMM ABLAUF ende

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;--- FUNKTIONEN

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    func bearbeiten()
    ;~ $Button1 = GUICtrlCreateButton("übernehmen",460,280,70,20)
    GUICtrlSetState($Button1, $GUI_SHOW)
    $nr = ControlListView("","",$listview,"GetSelected")
    $nr = $nr+1
    ;~ MsgBox(0,"",$aRecords[$nr])
    $Datensatz = StringSplit($aRecords[$nr],"|")
    ;~ MsgBox(0,"Datensatz hat n Elemente, n= ",$Datensatz[0])
    If $Datensatz[0] > 0 Then GUICtrlSetData($name,$Datensatz[1])
    If $Datensatz[0] > 1 Then GUICtrlSetData($vorname,$Datensatz[2])
    If $Datensatz[0] > 2 Then GUICtrlSetData($tel,$Datensatz[3])
    If $Datensatz[0] > 3 Then GUICtrlSetData($mobil,$Datensatz[4])
    If $Datensatz[0] > 4 Then GUICtrlSetData($handy,$Datensatz[5])
    ;~ _ArrayDisplay($Datensatz,"")
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func speichern()
    FileOpen($file,2 )
    For $x = 1 to $aRecords[0]
    FileWriteLine($file,$aRecords[$x])
    FileClose($file)
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    func anlegen()
    MsgBox(4096,"Datensatz anlegen","Bitte die entsprechenden Felder füllen" & @CR & @CR & 'Dann "hinzufügen" auswählen')
    ;~ $Button2 = GUICtrlCreateButton("hinzufügen",460,280,70,20)
    GUICtrlSetState($Button2, $GUI_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func hinzufuegen()
    $name_read = GUICtrlRead($name)
    $vorname_read = GUICtrlRead($vorname)
    $tel_read = GUICtrlRead($tel)
    $mobil_read = GUICtrlRead($mobil)
    $handy_read = GUICtrlRead($handy)
    $new = $aRecords[0]+1
    _ArrayInsert($aRecords,$new,$name_read & "|" & $vorname_read & "|" & $tel_read & "|" & $mobil_read & "|" & $handy_read)
    $aRecords[0] = $new
    speichern()
    refresh()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func uebernehmen()
    $name_read = GUICtrlRead($name)
    $vorname_read = GUICtrlRead($vorname)
    $tel_read = GUICtrlRead($tel)
    $mobil_read = GUICtrlRead($mobil)
    $handy_read = GUICtrlRead($handy)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ MsgBox(0,"",$name_read & "|" & $vorname_read & "|" & $tel_read & "|" & $mobil_read & "|" & $handy_read)
    _ArrayDelete($aRecords,$nr)
    _ArrayInsert($aRecords,$nr,$name_read & "|" & $vorname_read & "|" & $tel_read & "|" & $mobil_read & "|" & $handy_read)
    ;~ _ArrayDisplay($aRecords,"")
    refresh()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func loeschen()
    $nr = ControlListView("","",$listview,"GetSelected")
    $nr = $nr+1
    $new = $aRecords[0]-1

    [/autoit] [autoit][/autoit] [autoit]

    _ArrayDelete($aRecords,$nr)
    ;~ _ArrayDisplay($aRecords,"")
    $aRecords[0] = ""
    ;~ _ArraySort($aRecords)
    $aRecords[0] = $new
    ;~ _ArrayDisplay($aRecords,"")
    refresh()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    func refresh()
    $new = $aRecords[0]
    $aRecords[0] = ""
    _ArraySort($aRecords)
    $aRecords[0] = $new

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlDelete($listview)
    ;~ GUICtrlDelete($Button1)
    ;~ GUICtrlDelete($Button2)
    GUICtrlSetState($Button1, $GUI_HIDE)
    GUICtrlSetState($Button2, $GUI_HIDE)
    $listview = GUICtrlCreateListView ("Name |Vorname |Telefon|Schnurlos|Handy ",10,10,500,230);,$LVS_SORTDESCENDING)
    For $x = 1 to $aRecords[0]
    GUICtrlCreateListViewItem($aRecords[$x],$listview)
    Next
    GUICtrlSetState($listview ,$GUI_FOCUS)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _getLVItem_dbclick(ByRef $lvctrl)
    Dim $MousePos = GUIGetCursorInfo()
    If ($MousePos[4] == $lvctrl And GUICtrlRead($lvctrl) > 0 And _GUICtrlListViewGetHotItem ($lvctrl) = _GUICtrlListViewGetCurSel ($lvctrl)) Then
    $timerdiff = TimerDiff($TIMER)
    If $timerdiff <= $THRESHOLD Then
    $TIMER = TimerInit()
    bearbeiten()
    EndIf
    $TIMER = TimerInit()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    func _load_picture()
    sleep(500)
    $nr = ControlListView("","",$listview,"GetSelected")

    [/autoit] [autoit][/autoit] [autoit]

    $temp = StringSplit($aRecords[$nr+1], "|")
    ;~ _ArrayDisplay($temp, "")
    ;~ MsgBox(0,$nr , $temp)
    $Picture_file = "\\fs5\test\Mitarbeiter Fotos" & "\" & $temp[2] & " " & $temp[1] & ".jpg"
    ;~ GUICtrlDelete($picture)
    ;~ $picture = GUICtrlCreatePic($Picture_file, 540,30,199,150)
    ;~ GUISetState()
    GUICtrlSetImage($picture,$Picture_file)
    if Not FileExists($Picture_file) then
    GUICtrlSetImage($picture,"\\fs5\edv_inst\!!LOGINDIR\logo\dhl_exel_supply_chain_c.gif")
    SplashTextOn("Achtung", "kein Bild vorhanden",200,40)

    sleep(200)
    SplashOff()
    EndIf
    ;~ refresh()

    EndFunc


    [/autoit]

    Gruß
    Wolke

    • Offizieller Beitrag

    Hier stehen alle Codes!

    Virtual-Key Codes

    Man muss nur wissen welche Tasten das auf der US-Tastatur sind!

    Code
    ä = 0xDE -> For the US standard keyboard, the 'single-quote/double-quote' key
    ö = 0xC0 -> For the US standard keyboard, the '`~' key
    ü = 0xBA -> For the US standard keyboard, the ';:' key
  • Zitat

    Original von bernd670
    Man muss nur wissen welche Tasten das auf der US-Tastatur sind!

    ahaaaa wieder was dazugelehrnt. Ich hatte die Liste mit den Keys auch schon gefunden ... aber an die unterschiedlichen Tastaturlayouts nicht gedacht.

  • Zitat

    Original von th.meger
    Hi,

    sehr seltsam, ich kann sämtliche Tasten der gesamten Lappi-Tastatur quälen, ohne das sich auch nur irgendetwas in Sachen MsgBox tut. :(

    So long,

    Mega

    Du hattest Dich jetzt nicht auf meinen Quellcode bezogen ?

    Gruß
    Wolke