Opt("SendKeyDelay", 1) 
Opt ("WinWaitDelay", 1)
Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 4)
Opt("TrayMenuMode",1)
Opt("TrayOnEventMode", 1)

#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
; #include <ModernMenu.au3>
; #include <sampleGUIandTray.au3>
; #include <sample_Win2Tray.au3>
; #include <sampleGUIandTray-unicode.au3>

$settingsitem   = TrayCreateMenu("Settings")
$abouttray		= TrayCreateItem("About")
TrayItemSetOnEvent ($abouttray, "ABOUT")
$shortcut   = TrayCreateItem("Set Shortcut", $settingsitem)
TrayItemSetOnEvent ($shortcut, "SETTINGS")
$exititem       = TrayCreateItem("Exit")
TrayItemSetOnEvent ($exititem, "CLOSEClicked")
TraySetIcon("RegisCopyScript.exe")
TrayTip ( "Reg-IS CopyScript", "gestartet", "5")
TraySetToolTip ("Reg-IS CopyScript")


Func SETTINGS () 
	#Region ### START Koda GUI section ### Form=
	Global $Form1 = GUICreate("Shortcut", 180, 160, 193, 128)
	GUISetIcon("E:\REG-IS Archiv\_REG_IS 20090419\Favicon.ico")
	GUISetOnEvent($GUI_EVENT_CLOSE, "CloseSet")
	$CloseSet = GUICtrlCreateButton("Close", 40, 120, 97, 25, 0)
	GUICtrlSetOnEvent($CloseSet, "CloseSet")
	$SET = GUICtrlCreateButton("Set", 40, 90, 97, 25, 0)
	GUICtrlSetOnEvent($SET, "SET")
;	$ABOUT = GUICtrlCreateButton("About", 40, 150, 97, 25, 0)
;	GUICtrlSetOnEvent ($ABOUT, "ABOUT")
	Global $Input1 = GUICtrlCreateInput("", 75, 16, 33, 21)
	$Label1 = GUICtrlCreateLabel("alt = !", 30, 48, 30, 17)
	$Label2 = GUICtrlCreateLabel("shift = +", 30, 65, 41, 17)
	$Label3 = GUICtrlCreateLabel("strg = ^", 90, 48, 39, 17)
	$Label4 = GUICtrlCreateLabel("{F1} - {12}", 90, 65, 53, 17)
	GUISetState(@SW_SHOW)
	#EndRegion ### END Koda GUI section ###
		
EndFunc

;While 1
;$nMsg = GUIGetMsg()
;Switch $nMsg

;EndSwitch
;WEnd

While 1
	Sleep (1000)
WEnd

Func _copy ()
	send ("^c")
	$cache = ClipGet ()		; Zwischenspeicher auslesen
	$cache = StringRegExpReplace ( $cache,@crlf, " ")	; Umbrüche entfernen
	ClipPut ( $cache )	; Zwischenspeicher zurückschreiben
	WinActivate ("[CLASS:XLMAIN]", "")
	WinWaitActive ("[CLASS:XLMAIN]", "")
	MsgBox (48, "Cache", $cache)
;	send ( "{F2}" )
	send ( "^v")
;	send ( $cache )
	send ( "{ENTER}" )	; Zelle wechseln
	WinActivate ("[CLASS:AcrobatSDIWindow]", "")
	WinWaitActive ("[CLASS:AcrobatSDIWindow]", "")
EndFunc


Func CLOSEClicked ()
	Exit
EndFunc

	Func SET ()
	$key = GUICtrlRead ( $Input1 )
	if $key = "" Then
		MsgBox ( 48, "Fehler", "Bitte legen sie eine Tastenkombination fest!")
		Else
			MsgBox ( 64, "Meldung", "Tastenkombination wurde gesetzt" )
				$pdfexist = winExists ("classname=AcrobatSDIWindow", "")
				if $pdfexist = 1 Then
		GUISetState(@SW_MINIMIZE)
		WinActivate ("[CLASS:AcrobatSDIWindow]", "")
		WinWaitActive ("[CLASS:AcrobatSDIWindow]", "")
	Else
		 $pdfstart = MsgBox (36, "Es ist kein PDF-File geöffnet!", "Wollen sie jetzt eine Quellpdf öffnen?")
		
		if $pdfstart = 6 Then
			GUISetState(@SW_MINIMIZE)
;			shellexecute("acrobat.exe")
;			WinWaitActive ("[CLASS:AcrobatSDIWindow]", "")
;			send ("^o")
			$pdfdir = FileOpenDialog("PDF öffnen", "", "Adobe PDF Files (*.pdf)")
					if $pdfdir = "" Then 
					Else
					
;			MsgBox ( 1, "test", $pdfdir)
			send ( "{LWINDOWN}"&"{r}"&"{LWINUP}")
			WinWaitActive ("[CLASS:#32770]", "")
			Send ($pdfdir)
			Send ("{Enter}")
			WinWaitActive ("[CLASS:AcrobatSDIWindow]", "")
			Sleep (1000)
					EndIf
		Else
			
		EndIf
	
	EndIf

	$xlsexist = WinExists ("classname=XLMAIN", "")
		if $xlsexist = 1 Then
		GUISetState(@SW_MINIMIZE)
	WinActivate ("[CLASS:XLMAIN]", "")
	WinWaitActive ("[CLASS:XLMAIN]", "")
	Else
		$xlsstart = MsgBox (36, "Es ist kein Excel Tabelle geöffnet!", "Wollen sie jetzt eine Tabelle öffnen?")
		if $xlsstart = 6 Then
			GUISetState(@SW_MINIMIZE)
			$xlsdir = FileOpenDialog("XLS öffnen", "", "Excel-Datein (*.xls;*.xlsx)")
					if $xlsdir = "" Then
						Else
			send ( "{LWINDOWN}"&"{r}"&"{LWINUP}")
			WinWaitActive ("[CLASS:#32770]", "")
			Send ($xlsdir)
			Send ("{Enter}")
			WinWaitActive ("[CLASS:XLMAIN]", "")
;			Send ("{UP}")
					Endif			
		Else
			
		EndIf
	EndIf
		
		EndIf
		
	HotKeySet ( $key, "_copy")
	
	
	
	EndFunc
	
	Func ABOUT ()
		MsgBox ( 64, "About:", "Scriped by Daniel Glauche (d.glauche@gmx.de)")
	EndFunc
Func CloseSet ()
	GUISetState (@SW_HIDE)
	EndFunc