-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextplayer.ps1
80 lines (71 loc) · 2.42 KB
/
nextplayer.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
$COM = "COM4"
Function SendToPipe{
param (
[String]$Send
)
try {
$pipeClient = new-object System.IO.Pipes.NamedPipeClientStream(".", "DartOverlay", [System.IO.Pipes.PipeDirection]::Out)
$pipeClient.Connect(2000)
$pipeWriter = new-object System.IO.StreamWriter($pipeClient)
$pipeWriter.AutoFlush = $true
$pipeWriter.WriteLine($Send)
$pipeWriter.Close()
$pipeClient.Close()
}
catch{
Write-Output "Error on SendToPipe"
}
finally {
$pipeWriter.Close()
$pipeClient.Close()
$pipeWriter.Dispose()
$pipeClient.Dispose()
}
}
function read-com {
$port= new-Object System.IO.Ports.SerialPort $COM,9600,None,8,one
$port.Open()
do {
$line = $port.ReadLine()
Write-Host $line # Do stuff here
(get-date -Format "yyyy-MM-dd HH:mm:ss.fff") + ": " + ($line -replace "`t|`n|`r","") | out-file -Encoding Ascii -append c:\temp\nextplayer.log
if( $line -match "NextPlayer"){
Write-Host " -> Send {ENTER}"
SendToPipe -Send hide
SendWinDartEnter
}
if( $line -match "FoundPlayer"){
SendToPipe -Send show
#$Song = New-Object System.Media.SoundPlayer
#$Song.SoundLocation = "C:\WinDart\res_wav\dart.wav"
#$Song.Play()
}
if( $line -match "bRemain1Dart: 1|bGameOn: 0"){
SendToPipe -Send hide
}
}
while ($port.IsOpen)
}
function SendWinDartEnter{
Add-Type -AssemblyName System.Windows.Forms
$sig=@'
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
'@
$Dlls = @'
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
'@
$WindowControl = Add-Type -MemberDefinition $Dlls -Name "Win32WindowControl" -namespace Win32Functions -passThru
$w32 = Add-Type -Namespace Win32 -Name Funcs -MemberDefinition $sig -PassThru
$WindowHandle = $w32::FindWindow('TfrmCricket', '') # Windows PowerShell Console
If($WindowHandle){
$WindowControl::SetForegroundWindow($WindowHandle)
Start-Sleep -Milliseconds 10
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
}
}
Start-Process C:\Daten\WinDart\WindartOverlay.exe -ArgumentList "/hide /opacity 40"
read-com