2013-12-21 3 views
0

응용 프로그램에 키 입력을 보낼 수있는 다른 방법이 있습니까?Sendkeys Powershell이 ​​제대로 작동하지 않습니다.

콘솔을 응용 프로그램에서 열어야하는 백틱 키를 누른 후에이 Powershell 스크립트를 사용하지만이 경우는 발생하지 않지만 키보드는 phisical 한 방식으로 완벽하게 작동합니다.

본인이 직접 콘솔을 열면 sendkeys는 작동하지만 첫 번째 sendkeys (backtick)가 작동하지 않습니다.

내가 필요한 것은 스크립트가 백틱 키를 보내서 콘솔을 여는 것입니다. 내가 볼

# startpwsscrip.ps1 

function wait { 
    param([int]$stop = 8) 
    Start-Sleep -seconds $stop 
} 

[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic") 
& "$env:C:\Program Files (x86)\Steam\SteamApps\common\Half-Life\cstrike.exe" 
$a = Get-Process | Where-Object {$_.Name -eq "Counter-strike"} 
wait3 
$Cursor = [system.windows.forms.cursor]::Clip 
[System.Windows.Forms.Cursor]::Position = New-Object system.drawing.point(509,763) 
wait 
[System.Windows.Forms.SendKeys]::SendWait({"ENTER"}) 
wait 
[System.Windows.Forms.SendKeys]::SendWait({"`"}) 
wait 
[System.Windows.Forms.SendKeys]::SendWait("connect ") 
wait 
[System.Windows.Forms.SendKeys]::SendWait("192.168.1.1") 
wait 
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}") 

답변

0

첫 번째 문제는 System.Windows.Forms를 참조하지 않는 당신이 잘되지 않을 수 있습니다 비쥬얼 기준에 추가 한 인용문이있다.

add-type -AssemblyName System.Windows.Forms 

#or 

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

여기에 작은 따옴표가 있습니다. 역 따옴표는 특수 문자로

("'Microsoft.VisualBasic") 
# should be one or the other 
('Microsoft.VisualBasic') 
("Microsoft.VisualBasic") 

"대기"또는 "wait3는 '는 PS1 방법이 아닙니다, 이중 역 따옴표를 사용하려고 시작 - 슬립 1

Start-Sleep 1 
Start-Sleep 3 
+0

이 백틱에 관해서는, 내가 그 버튼을 SendKeys 매크로 어떤 문서 ATM을 찾을 수 없습니다. 그러나 우리가 그것을 어떻게 벗어나야할지에 관해 좋은 읽을 거리가 있습니다. http://www.rlmueller.net/PowerShellEscape.htm –

+1

SendKeys는 지역 설정 (키보드 레이아웃)에 따라 다르므로 다양 할 수 있습니다. Shift 키를 누른 상태에서'\'와 스페이스를 눌러 백틱을 생성합니다. 생성하려면'[System.Windows.Forms.SendKeys] :: SendWait ("+ \")'를 사용하십시오. '+'는 시프트를 누르고 있음을 의미합니다. –

0

을 시도합니다. 다른 탈출 하나,이 방법 :

[System.Windows.Forms.SendKeys] :: SendWait ("``")

0

백틱 두 번 인용 문자열 내에서 이스케이프 문자입니다. 작은 따옴표로 묶인 문자열의 내용은 문자 그대로 해석되므로 작은 따옴표로 묶은 문자열을 사용해야합니다. 또한 문자열 주위에 중괄호가 필요하지 않습니다.

[System.Windows.Forms.SendKeys]::SendWait('`') 

은 참조 :

help about_Quoting_Rules 
help about_Escape_Characters 
관련 문제