2013-04-08 1 views
0

나는 이미 내 sendkeys 응용 프로그램을 만들어 내 인생을 더 쉽게 만들 수 있도록 도와 주지만, 나는 창문을 바꿀 때 sendkey를 끄는 것을 잊어 버렸습니다. 응용 프로그램은 내가 멈출 때까지 메모장 (현재 활성 응용 프로그램)에 "123123"을 보냅니다. 그래서 msword로 전환하면 작동하지 않습니다. 다시 메모장으로 다시 전환하면 sendkeys가 다시 활성화됩니다. 생활이vb.net 특정 활성 응용 프로그램에 sendkeys

If activeWindows = notepad.exe then 
    do this 
Else 
    do nothing 
End If 

같은 일부 인수는 그냥 생각입니다하지만 난 vb.net에서 그런 일을하는 방법을 잘 모릅니다, 나는 내가 그것을 생각 애플리케이션 원인의 제목 대신 .EXE 사용하려는 경우 내가하는 일에 많은 도움이된다.

답변

0

예, 그것은 작동합니다 사전에

들으, 좋은 생각. 지금까지 numLock 키를 읽는 것이 었습니다. 켜져있는 한, sendkeys가있는 타이머가 실행 중입니다. 꺼지 자마자 타이머도 멈 춥니 다. 그러나 현재 포커스에 대한 체크를 추가하는 것은 좋은 추가 일 것입니다.

사용하는 어떤 방법이를 확인하십시오, 나는 그것이 How do I find the program with the current focus?

0

당신은 당신을 위해이 작업을 수행 할 GetForegroundWindowGetWindowThreadProcessId API를 사용할 수있는 맞는 생각합니다. 다음은 간단한 예입니다.

''' <summary>The GetForegroundWindow function returns a handle to the foreground window.</summary> 
''' <returns>The return value is a handle to the foreground window. The foreground window can be NULL in certain circumstances, such as when a window is losing activation. </returns> 
<DllImport("user32.dll", SetLastError:=True)> _ 
Private Shared Function GetForegroundWindow() As IntPtr 
End Function 

<DllImport("user32.dll", SetLastError:=True)> _ 
Private Shared Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, _ 
         ByRef lpdwProcessId As Integer) As Integer 
End Function 

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 

    Task.Run(AddressOf KeySender) 

End Sub 

Private Sub KeySender() 
    While (True) 

     Dim fgWin = GetForegroundWindow() 
     Dim fgPid As New Integer() 
     GetWindowThreadProcessId(fgWin, fgPid) 

     Dim proc = System.Diagnostics.Process.GetProcessById(fgPid) 
     Console.WriteLine(proc.ProcessName) 

     If (proc.ProcessName = "notepad") Then 
      SendKeys.SendWait("A") 
     End If 


     System.Threading.Thread.Sleep(1000) 

    End While 
End Sub 
관련 문제