GUI im Vordergrund

  • Hi.
    Ich bin grade dabei eine Bildschirmtastatur zu machen.
    Als ich grad die Buttons mache fällt mir ein dass ich versuchen sollte ob die Buttons überhaupt funktionieren.
    Ich habe dann die Tastatur geöffnet und so weiter und dann wollte ich etwas bei Word eingeben.
    Aber wenn ich auf einen Button klicke dann springt die Tastatur in den Vordergrund und es wird nichts geschrieben.
    Bis jetzt funktioniert nur der 1 Button weil ich wollte es ja nur ausprobieren.
    Gibt es eine Möglichkeit, dass die Tastatur schreibt??


    [autoit]

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

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

    $Fenster1 = GUICreate("Tastertur", 500, 150)
    $haeckchenbutton = GUICtrlCreateButton("^",2,3,30,30)
    $1button = GUICtrlCreateButton("1",32, 3, 30, 30)
    $2button = GUICtrlCreateButton("2",62,3,30,30)
    $3button = GUICtrlCreateButton("3",92,3,30,30)
    $4button = GUICtrlCreateButton("4",122,3,30,30)
    $5button = GUICtrlCreateButton("5",152,3,30,30)
    $6button = GUICtrlCreateButton("6",182,3,30,30)
    $7button = GUICtrlCreateButton("7",212,3,30,30)
    $8button = GUICtrlCreateButton("8",242,3,30,30)
    $9button = GUICtrlCreateButton("9",272,3,30,30)
    $0button = GUICtrlCreateButton("0",302,3,30,30)
    $scharfesSbutton = GUICtrlCreateButton("ß",332,3,30,30)
    $Strichbutton = GUICtrlCreateButton("`",362,3,30,30)
    $deletebutton = GUICtrlCreateButton("del",392,3,30,30)
    $Tabbutton = GUICtrlCreateButton("Tab",2,33,30,30)
    $qbutton = GUICtrlCreateButton("Q",32,33,30,30)
    $wbutton = GUICtrlCreateButton("W",62,33,30,30)
    $ebutton = GUICtrlCreateButton("E",92,33,30,30)
    $rbutton = GUICtrlCreateButton("R",122,33,30,30)
    $tbutton = GUICtrlCreateButton("T",152,33,30,30)
    $zbutton = GUICtrlCreateButton("Z",182,33,30,30)
    $ubutton = GUICtrlCreateButton("U",212,33,30,30)
    $ibutton = GUICtrlCreateButton("I",242,33,30,30)
    $obutton = GUICtrlCreateButton("O",272,33,30,30)
    $pbutton = GUICtrlCreateButton("P",302,33,30,30)
    $uebutton = GUICtrlCreateButton("Ü",302,33,30,30)
    $Plusbutton = GUICtrlCreateButton("+",332,33,30,30)
    $Enterbutton = GUICtrlCreateButton("Enter", 362,33,60,60)
    $Umschalteinbutton = GUICtrlCreateButton("Umsch ON",2,63,60,30)
    $abutton = GUICtrlCreateButton("A",62,63,30,30)
    $sbutton = GUICtrlCreateButton("S",92,63,30,30)
    $dbutton = GUICtrlCreateButton("D",122,63,30,30)
    $fbutton = GUICtrlCreateButton("F",152,63,30,30)
    $gbutton = GUICtrlCreateButton("G",182,63,30,30)
    GUISetState(@SW_Show)

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

    While 1

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

    $msg = GUIGetMsg()

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

    Select
    Case $msg = $1button
    Send("1")
    Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
    EndSelect
    WEnd

    [/autoit]

    Danke, für eure Hilfe

  • ja das funktioniert...
    schau dir die control funktionen an

    bsp mit editor:

    Spoiler anzeigen
    [autoit]

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

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

    $Fenster1 = GUICreate("Tastertur", 500, 150)
    $haeckchenbutton = GUICtrlCreateButton("^",2,3,30,30)
    $1button = GUICtrlCreateButton("1",32, 3, 30, 30)
    $2button = GUICtrlCreateButton("2",62,3,30,30)
    $3button = GUICtrlCreateButton("3",92,3,30,30)
    $4button = GUICtrlCreateButton("4",122,3,30,30)
    $5button = GUICtrlCreateButton("5",152,3,30,30)
    $6button = GUICtrlCreateButton("6",182,3,30,30)
    $7button = GUICtrlCreateButton("7",212,3,30,30)
    $8button = GUICtrlCreateButton("8",242,3,30,30)
    $9button = GUICtrlCreateButton("9",272,3,30,30)
    $0button = GUICtrlCreateButton("0",302,3,30,30)
    $scharfesSbutton = GUICtrlCreateButton("ß",332,3,30,30)
    $Strichbutton = GUICtrlCreateButton("`",362,3,30,30)
    $deletebutton = GUICtrlCreateButton("del",392,3,30,30)
    $Tabbutton = GUICtrlCreateButton("Tab",2,33,30,30)
    $qbutton = GUICtrlCreateButton("Q",32,33,30,30)
    $wbutton = GUICtrlCreateButton("W",62,33,30,30)
    $ebutton = GUICtrlCreateButton("E",92,33,30,30)
    $rbutton = GUICtrlCreateButton("R",122,33,30,30)
    $tbutton = GUICtrlCreateButton("T",152,33,30,30)
    $zbutton = GUICtrlCreateButton("Z",182,33,30,30)
    $ubutton = GUICtrlCreateButton("U",212,33,30,30)
    $ibutton = GUICtrlCreateButton("I",242,33,30,30)
    $obutton = GUICtrlCreateButton("O",272,33,30,30)
    $pbutton = GUICtrlCreateButton("P",302,33,30,30)
    $uebutton = GUICtrlCreateButton("Ü",302,33,30,30)
    $Plusbutton = GUICtrlCreateButton("+",332,33,30,30)
    $Enterbutton = GUICtrlCreateButton("Enter", 362,33,60,60)
    $Umschalteinbutton = GUICtrlCreateButton("Umsch ON",2,63,60,30)
    $abutton = GUICtrlCreateButton("A",62,63,30,30)
    $sbutton = GUICtrlCreateButton("S",92,63,30,30)
    $dbutton = GUICtrlCreateButton("D",122,63,30,30)
    $fbutton = GUICtrlCreateButton("F",152,63,30,30)
    $gbutton = GUICtrlCreateButton("G",182,63,30,30)
    GUISetState(@SW_Show)

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

    While 1

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

    $msg = GUIGetMsg()

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

    Select
    Case $msg = $1button
    ControlSend("Unbenannt - Editor","","Edit1","1")
    Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
    EndSelect
    WEnd

    [/autoit]

    Dann müsstest du halt noch ein Code entwickeln, der rausfindet, welches Fenster du zuletzt aktiv hattest, und in welches "Schreib- Feld" du zuletzt geklickt hast.


    Greez

    • Offizieller Beitrag

    Ich hatte mal so ein Script geschrieben:

    Spoiler anzeigen
    [autoit]


    #include <Constants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>
    Opt('GUIOnEventMode', 1)
    Opt('TrayMenuMode', 1)
    Global $bShift = False, $bLock = False, $bOld = False, $ahKeys[57], $wHWND, $cHWND
    Global $sTitle = 'Mouse-Keyboard v1.4 by Oscar (http://www.autoit.de)'
    Global $aKeys[57][6] = [ _
    ['^', '°', 010, 060, 32, 32],['1', '!', 044, 060, 32, 32],['2', '"', 078, 060, 32, 32],['3', '§', 112, 060, 32, 32], _
    ['4', '$', 146, 060, 32, 32],['5', '%', 180, 060, 32, 32],['6', '&&', 214, 060, 32, 32],['7', '/', 248, 060, 32, 32], _
    ['8', '(', 282, 060, 32, 32],['9', ')', 316, 060, 32, 32],['0', '=', 350, 060, 32, 32],['ß', '?', 384, 060, 32, 32], _
    ['´', '`', 418, 060, 32, 32],['<-', '<-', 452, 060, 66, 32], _
    ['q', 'Q', 010, 100, 32, 32],['w', 'W', 044, 100, 32, 32],['e', 'E', 078, 100, 32, 32],['r', 'R', 112, 100, 32, 32], _
    ['t', 'T', 146, 100, 32, 32],['z', 'Z', 180, 100, 32, 32],['u', 'U', 214, 100, 32, 32],['i', 'I', 248, 100, 32, 32], _
    ['o', 'O', 282, 100, 32, 32],['p', 'P', 316, 100, 32, 32],['ü', 'Ü', 350, 100, 32, 32],['*', '+', 384, 100, 32, 32], _
    ['@', '|', 418, 100, 32, 32],['[', '\', 452, 100, 32, 32],[']', '~', 486, 100, 32, 32], _
    ['a', 'A', 010, 140, 32, 32],['s', 'S', 044, 140, 32, 32],['d', 'D', 078, 140, 32, 32],['f', 'F', 112, 140, 32, 32], _
    ['g', 'G', 146, 140, 32, 32],['h', 'H', 180, 140, 32, 32],['j', 'J', 214, 140, 32, 32],['k', 'K', 248, 140, 32, 32], _
    ['l', 'L', 282, 140, 32, 32],['ö', 'Ö', 316, 140, 32, 32],['ä', 'Ä', 350, 140, 32, 32],['#', "'", 384, 140, 32, 32], _
    ['LOCK', 'LOCK', 418, 140, 100, 32], _
    ['y', 'Y', 010, 180, 32, 32],['x', 'X', 044, 180, 32, 32],['c', 'C', 078, 180, 32, 32],['v', 'V', 112, 180, 32, 32], _
    ['b', 'B', 146, 180, 32, 32],['n', 'N', 180, 180, 32, 32],['m', 'M', 214, 180, 32, 32],[',', ';', 248, 180, 32, 32], _
    ['.', ':', 282, 180, 32, 32],['-', '_', 316, 180, 32, 32],['<', '>', 350, 180, 32, 32],['€', 'µ', 384, 180, 32, 32], _
    ['SHIFT', 'SHIFT', 418, 180, 100, 32], _
    ['SPACE', 'SPACE', 10, 220, 406, 32],['ENTER', 'ENTER', 418, 220, 100, 32] _
    ]
    $hGui = GUICreate($sTitle, 530, 280)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_End')
    GUISetIcon('shell32.dll', -174, $hGui)
    GUISetBkColor(0xCCCCCC)
    GUICtrlCreateLabel('Send input to (Window-Title):', 10, 10, 500, 16)
    $hSendWindow = GUICtrlCreateLabel(' Select a Window!', 10, 30, 508, 18, $SS_SUNKEN)
    GUICtrlSetFont(-1, 9, 400, 0, 'Arial')
    GUICtrlSetBkColor(-1, 0xFF6666)

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

    For $i = 0 To UBound($aKeys) - 1
    $ahKeys[$i] = GUICtrlCreateButton($aKeys[$i][0], $aKeys[$i][2], $aKeys[$i][3], $aKeys[$i][4], $aKeys[$i][5])
    GUICtrlSetFont(-1, 14, 400, 0, 'Courier New')
    GUICtrlSetOnEvent(-1, '_Key')
    Next
    $hStatus = GUICtrlCreateLabel(' Status: NORMAL', -2, 264, 534, 16, Default, $WS_EX_STATICEDGE)
    GUICtrlSetBkColor(-1, 0xBBBBBB)
    TraySetIcon('shell32.dll', -174)
    TraySetClick(16)
    TrayCreateItem($sTitle)
    TrayItemSetState(-1, $TRAY_DISABLE)
    TrayCreateItem('')
    TrayCreateItem('Exit')
    TrayItemSetOnEvent(-1, '_End')

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

    GUISetState()
    WinSetOnTop($hGui, '', 1)

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

    While True
    If $wHWND <> WinGetHandle('') And WinGetHandle('') <> $hGui Then
    $wHWND = WinGetHandle('')
    $cHWND = ControlGetFocus($wHWND)
    GUICtrlSetData($hSendWindow, WinGetTitle($wHWND))
    GUICtrlSetBkColor($hSendWindow, 0x66FF66)
    Else
    Sleep(100)
    EndIf
    WEnd

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

    Func _End()
    Exit
    EndFunc ;==>_End

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

    Func _Key()
    Local $sKey = GUICtrlRead(@GUI_CtrlId)
    Switch $sKey
    Case '<-'
    ControlSend($wHWND, '', $cHWND, '{BACKSPACE}')
    Case 'LOCK'
    $bShift = False
    $bLock = True
    GUICtrlSetData($hStatus, ' Status: CAPS LOCK')
    _Shift()
    Case 'SHIFT'
    GUICtrlSetData($hStatus, ' Status: SHIFT')
    _Shift()
    $bLock = False
    Case 'SPACE'
    ControlSend($wHWND, '', $cHWND, '{SPACE}')
    Case 'ENTER'
    ControlSend($wHWND, '', $cHWND, '{ENTER}')
    Case '&&'
    ControlSend($wHWND, '', $cHWND, '{&}')
    If $bShift And Not $bLock Then _Shift()
    Case Else
    ControlSend($wHWND, '', $cHWND, $sKey)
    If $bShift And Not $bLock Then _Shift()
    EndSwitch
    EndFunc ;==>_Key

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

    Func _Shift()
    $bShift = Not $bShift
    If Not $bShift Then GUICtrlSetData($hStatus, ' Status: NORMAL')
    If $bShift = $bOld Then Return
    $bOld = $bShift
    For $i = 0 To UBound($aKeys) - 1
    GUICtrlSetData($ahKeys[$i], $aKeys[$i][$bShift])
    Next
    EndFunc ;==>_Shift

    [/autoit]
    • Offizieller Beitrag

    So schwer ist das doch nicht:
    ControlSend benötigt das Handle des Windows sowie des Control-Elements, an das die Zeichen gesendet werden sollen. Diese werden in der While...WEnd-Schleife (Zeile 55...64) ermittelt und in den globalen Variablen "$wHWND" und "$cHWND" gespeichert. In der Funktion "_Key" werden diese Variablen dann von den ControlSend-Befehlen benutzt.