HotKeySet Frage

  • Hi

    Ich will ein kleines Programm schreiben und bräuchte da die Funktion dass sich bei den pfeiltasten der Schwarze Kasten Verschiebt und zwar jedes mal in die richtung die man drückt

    Folgendes habe ich bisher:

    Spoiler anzeigen
    [autoit]

    #include <gui.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #NoTrayIcon
    HotKeySet("{Down}")
    HotKeySet("{Up}")
    HotKeySet("{Right}")
    HotKeySet("{Left}")

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

    GUICreate("SB Game",@DesktopWidth,@Desktopheight,0,0,$WS_POPUP)
    GUISetBkColor(0xCDAD00)
    $mainmenu = GUICTrlCreateMenu("Datei")
    $exititem = GUICtrlCreatemenuitem("Beenden",$mainmenu)

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

    GUICtrlCreateLabel("",10,10,30,30)
    GUICTrlSEtBkColor(-1,0x000000)

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

    GUISEtState()

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

    While 1
    $msg = GUIGEtMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $exititem
    Exit
    EndSwitch
    Wend

    [/autoit]

    Ich hoffe mir kann jemand helfen.

    mfg. Simon :?:

  • hey ich würds so machen:

    [autoit]

    #include <gui.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #NoTrayIcon
    HotKeySet("{Down}", "_dMove")
    HotKeySet("{Up}", "_uMove")
    HotKeySet("{Right}", "_rMove")
    HotKeySet("{Left}", "_lMove")

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

    Global $1Pos = 10
    Global $2Pos = 10

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

    GUICreate("SB Game",@DesktopWidth,@Desktopheight,0,0,$WS_POPUP)
    GUISetBkColor(0xCDAD00)
    $mainmenu = GUICTrlCreateMenu("Datei")
    $exititem = GUICtrlCreatemenuitem("Beenden",$mainmenu)

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

    $Ball = GUICtrlCreateLabel("",10,10,30,30)
    GUICTrlSEtBkColor(-1,0x000000)

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

    GUISEtState()

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

    While 1
    $msg = GUIGEtMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $exititem
    Exit
    EndSwitch
    Wend

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

    Func _rMove()
    GUICtrlDelete($Ball)
    $1Pos = $1Pos+30
    $Ball = GUICtrlCreateLabel("",$1Pos,$2Pos,30,30)
    GUICTrlSEtBkColor(-1,0x000000)
    EndFunc

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

    Func _lMove()
    GUICtrlDelete($Ball)
    $1Pos = $1Pos-30
    $Ball = GUICtrlCreateLabel("",$1Pos,$2Pos,30,30)
    GUICTrlSEtBkColor(-1,0x000000)
    EndFunc

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

    Func _dMove()
    GUICtrlDelete($Ball)
    $2Pos = $2Pos+30
    $Ball = GUICtrlCreateLabel("",$1Pos,$2Pos,30,30)
    GUICTrlSEtBkColor(-1,0x000000)
    EndFunc

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

    Func _uMove()
    GUICtrlDelete($Ball)
    $2Pos = $2Pos-30
    $Ball = GUICtrlCreateLabel("",$1Pos,$2Pos,30,30)
    GUICTrlSEtBkColor(-1,0x000000)
    EndFunc

    [/autoit]


    hfgl team2way :thumbup:

  • Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    HotKeySet("{Down}", "_down")
    HotKeySet("{Up}", "_up")
    HotKeySet("{Right}", "_right")
    HotKeySet("{Left}", "_left")

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

    Global $posx = 10, $posy = 10, $speed = 10

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

    $Form1 = GUICreate("SB Game", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
    GUISetBkColor(0xCDAD00)

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

    $mainmenu = GUICtrlCreateMenu("Datei")
    $exititem = GUICtrlCreateMenuItem("Beenden", $mainmenu)

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

    $label1 = GUICtrlCreateLabel("", 10, 10, 30, 30)
    GUICtrlSetBkColor(-1, 0x000000)

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

    GUISetState()

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

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $exititem
    Exit
    EndSwitch
    WEnd

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

    Func _down()
    $posy += $speed
    If $posy >= @DesktopHeight Then $posy = 0
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_down

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

    Func _up()
    $posy -= $speed
    If $posy <= 0 Then $posy = @DesktopHeight
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_up

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

    Func _right()
    $posx += $speed
    If $posx >= @DesktopWidth Then $posx = 0
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_right

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

    Func _left()
    $posx -= $speed
    If $posx <= 0 Then $posx = @DesktopWidth
    ControlMove($Form1, "", $label1, $posx, $posy)
    EndFunc ;==>_left

    [/autoit]
  • und wie kann ich es machen dass wenn der orange Kasten den Schwarzen Berührt dass er dann Stehen Bleibt


    hier mein Bisheriger Code:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    HotKeySet("{Down}", "_down")
    HotKeySet("{Up}", "_up")
    HotKeySet("{Right}", "_right")
    HotKeySet("{Left}", "_left")

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

    Global $posx = 10, $posy = 10, $speed = 30

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

    $Form1 = GUICreate("SB Game", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
    GUISetBkColor(0xCDAD00)

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

    $mainmenu = GUICtrlCreateMenu("Datei")
    $exititem = GUICtrlCreateMenuItem("Beenden", $mainmenu)

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

    $label1 = GUICtrlCreateLabel("", 10, 10, 30, 30)
    GUICtrlSetBkColor(-1, 0xFFCC33)

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

    GUICTrlCreateLabel("",100,50,60,300)
    GUICTrlSEtBkColor(-1,0x000000)

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

    GUISetState()

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

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $exititem
    Exit
    EndSwitch
    WEnd

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

    Func _down()
    $posy += $speed
    If $posy >= @DesktopHeight Then $posy = 0
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_down

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

    Func _up()
    $posy -= $speed
    If $posy <= 0 Then $posy = @DesktopHeight
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_up

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

    Func _right()
    $posx += $speed
    If $posx >= @DesktopWidth Then $posx = 0
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_right

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

    Func _left()
    $posx -= $speed
    If $posx <= 0 Then $posx = @DesktopWidth
    ControlMove($Form1, "", $label1, $posx, $posy)
    EndFunc ;==>_left

    [/autoit]

    Ich hofe mir kann jemand helfen

    mfg. Simon

  • Hey, nur mal ein kleiner Tipp
    Ich würde das Nicht mit HotKeySet machen, da das immer funktionuert egal ob das fenster inativ ist oder gelöscht wird, ich würde 4 buton machen und auf die HotKeys setzen das ist dann nähmlich nur wenn das fenster active ist, man kann in der Func die durch hotkeyset ausgeführt wird natürlich auch überprüfen ob das Fenster active ist, aber das hat dann den nachteil das diese Tastenkombi nur noch in dem Programm benutz werden kann, wenn ein anderes Programm die gleichen hat gibt es Probleme, das ist nicht, wenn du es mit Button machst!

    mfg. Jam00

  • das ist schon mal ein anfang - du musst den bereich jetzt nur noch weiter eingrenzen...

    [autoit]

    Global $po...
    Opt("GUIOnEventMode", 1)

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

    $Form1 = GUICreate("SB Game", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
    GUISetBkColor(0xCDAD00)

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

    $mainmenu = GUICtrlCreateMenu("Datei")
    $exititem = GUICtrlCreateMenuItem("Beenden", $mainmenu)
    GUICtrlSetOnEvent(-1,"_Exit")

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

    ;...

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

    GUISetState()

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

    While 1
    If $posx >= 100 Then
    MsgBox(0,"","Hinderniss berührt", 3)
    Sleep(1000)
    EndIf
    WEnd

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

    Func _Exit()
    Exit
    EndFunc

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

    ;...

    [/autoit]


    hab die while schleife ersetzt und exit auf onevent gesetzt ^^

  • Bei mir kommt hier aber immer die MsgBox

    Code:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    HotKeySet("{Down}", "_down")
    HotKeySet("{Up}", "_up")
    HotKeySet("{Right}", "_right")
    HotKeySet("{Left}", "_left")

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

    Global $posx = 10, $posy = 10, $speed = 30

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

    Opt("GUIOnEventMode", 1)

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

    $Form1 = GUICreate("SB Game", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
    GUISetBkColor(0xCDAD00)

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

    $mainmenu = GUICtrlCreateMenu("Datei")
    $exititem = GUICtrlCreateMenuItem("Beenden", $mainmenu)
    GUICtrlSetOnEvent(-1,"_Exit")

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

    $label1 = GUICtrlCreateLabel("", 10, 10, 30, 30)
    GUICtrlSetBkColor(-1, 0xFFCC33)

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

    GUICTrlCreateLabel("",100,50,60,300)
    GUICTrlSEtBkColor(-1,0x000000)

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

    GUISetState()

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

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $exititem
    Exit
    Case $posx >= 100
    MsgBox(0,"","Hinderniss berührt", 3)
    Sleep(1000)

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

    EndSwitch
    WEnd

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

    Func _down()
    $posy += $speed
    If $posy >= @DesktopHeight Then $posy = 0
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_down

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

    Func _up()
    $posy -= $speed
    If $posy <= 0 Then $posy = @DesktopHeight
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_up

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

    Func _right()
    $posx += $speed
    If $posx >= @DesktopWidth Then $posx = 0
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_right

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

    Func _left()
    $posx -= $speed
    If $posx <= 0 Then $posx = @DesktopWidth
    ControlMove($Form1, "", $label1, $posx, $posy)
    EndFunc ;==>_left

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

    Func _Exit()
    Exit
    EndFunc

    [/autoit]
  • So, hier mal ein Beispiel wie man HotKeys auf Button legt:

    Spoiler anzeigen
    [autoit]

    $Form1 = GUICreate("utton-HotKey", 245, 60, 193, 125)
    $Button1 = GUICtrlCreateButton("Leertaste", 78, 4, 75, 25, 0)
    $Button2 = GUICtrlCreateButton("Enter", 78, 30, 75, 25, 0)
    GUISetState(@SW_SHOW)
    Dim $Form1_AccelTable[2][2] = [["{SPACE}", $Button1],["{ENTER}", $Button2]]
    GUISetAccelerators($Form1_AccelTable)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case -3
    Exit
    Case $Button1
    MsgBox (0,"Gedrückt","Der Button 'Leertaste' wurde gedrückt!")
    Case $Button2
    MsgBox (0,"Gedrückt","Der Button 'Enter' wurde gedrückt!")
    EndSwitch
    WEnd

    [/autoit]

    mfg. Jam00

  • Ich habe jetzt das Problemm dass auch hinter und unter der Mauer die Meldung kommt dass ich dss hinderniss berühre was aber ja nicht stimmt und ich kenne mich jetzt nicht aus wiso dass So ist

    Qellcode:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    HotKeySet("{Down}", "_down")
    HotKeySet("{Up}", "_up")
    HotKeySet("{Right}", "_right")
    HotKeySet("{Left}", "_left")

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

    Global $posx = 10, $posy = 10, $speed = 30

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

    Opt("GUIOnEventMode", 1)

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

    $Form1 = GUICreate("SB Game", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
    GUISetBkColor(0xCDAD00)

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

    $mainmenu = GUICtrlCreateMenu("Datei")
    $exititem = GUICtrlCreateMenuItem("Beenden", $mainmenu)
    GUICtrlSetOnEvent(-1,"_Exit")

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

    $label1 = GUICtrlCreateLabel("", 10, 10, 30, 30)
    GUICtrlSetBkColor(-1, 0xFFCC33)

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

    GUICTrlCreateLabel("",100,50,60,300)
    GUICTrlSEtBkColor(-1,0x000000)

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

    GUISetState()

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

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $exititem
    Exit
    EndSwitch
    If ($posx >= 60 And $posx >= 70) And ($posy >= 50 And $posy >= 60) Then
    MsgBox(0,"","Hinderniss berührt")
    Sleep(1000)
    EndIf
    WEnd

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

    Func _down()
    $posy += $speed
    If $posy >= @DesktopHeight-5 Then $posy = 0
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_down

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

    Func _up()
    $posy -= $speed
    If $posy <= 0 Then $posy = @DesktopHeight-5
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_up

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

    Func _right()
    $posx += $speed
    If $posx >= @DesktopWidth-5 Then $posx = 0
    ControlMove("", "", $label1, $posx, $posy)
    EndFunc ;==>_right

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

    Func _left()
    $posx -= $speed
    If $posx <= 0 Then $posx = @DesktopWidth-5
    ControlMove($Form1, "", $label1, $posx, $posy)
    EndFunc ;==>_left

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

    Func _Exit()
    Exit
    EndFunc

    [/autoit]

    ich hoffe mir kann da jemand helfen

    mfg. Simon

  • ich würd das mit _ispressed machen. Und mit dem Berühren: Du musst wissen wie groß der "Ball" ist, und dann in etwa so:

    [autoit]

    if $ballpos + $größe des balls = $wandpos + $größederwand then blablabla ; Das ganze mit den x und mit den y koordinaten ... Sry wenn ich nunverständlich bin :p

    [/autoit]

    MFG Scripter192