[英]redirect input from keyboard like device to background process in windows environment
I use simple RFID reader device which connected to PC with usb cable and identified as keyboard like device. 我使用简单的RFID读取器设备,该设备通过USB电缆连接到PC,并被识别为类似键盘的设备。 I want to read input from this device by my application but it is running in background ie other application is in focus. 我想通过我的应用程序从此设备读取输入,但是它在后台运行,即其他应用程序处于焦点。 How can I redirect stdin to my application in windows 7 environment? 如何在Windows 7环境中将stdin重定向到我的应用程序? I can't change focus to my application I can't make change in front application (eg catch stdin and send it to my application via pipe etc.) My application is written in C# but I can rewrite it to Java / C The PC runs Win 7 OS. 我无法将重点转移到我的应用程序上,也无法在前端应用程序中进行更改(例如,捕获标准输入并通过管道将其发送到我的应用程序中。)我的应用程序是用C#编写的,但是我可以将其重写为Java / C。运行Win 7 OS。
Thanks y 谢谢你
Here my solution: 这是我的解决方案:
I have connected a normal Keyboard and a Card Reader via USB to my computer. 我已经通过USB将普通的键盘和读卡器连接到计算机上。
Both devices write to the windows keyboard buffer. 两种设备均写入Windows键盘缓冲区。
I want to redirect the input of the Card Reader to another application or file and remove it from the keyboard buffer (so that this input will not show up in any editor). 我想将读卡器的输入重定向到另一个应用程序或文件, 并将其从键盘缓冲区中删除 (这样该输入将不会在任何编辑器中显示)。
What I know / Prerequisites: 我所知道的/先决条件:
What I do: 我所做的:
Here my program (written in the script language AutoHotkey ): 这是我的程序(用脚本语言AutoHotkey编写):
KeybRedir.ahk KeybRedir.ahk
; KeybRedir
; Programmiert von Michael Hutter - Mai 2018
#NoEnv ;Avoids checking empty variables to see if they are environment variables
#SingleInstance force
Process, Priority, , Normal
#Warn All
SaveKeyList=
0::
1::
2::
3::
4::
5::
6::
7::
8::
9::
+A::
+B::
+C::
+D::
+E::
+F::
Return::
{ ; If one of these characters was typed => take it out of windows key buffer...
if A_ThisHotkey = Return
Hotkey:=Chr(13)
else
Hotkey:=A_ThisHotkey
SaveKeyList = %SaveKeyList%%Hotkey%
SetTimer , DoKeyPlay, 70 ; Wait 70ms for another key press of charlist (re-trigger the timer in case it already runs)
}
return
DoKeyPlay:
SetTimer , , Off
SaveText:=RegExReplace(SaveKeyList, "\+", "")
StringReplace, SaveText, SaveText, `r, , All
if StrLen(SaveText) < 4 ; Accumulated text size < 4 letters => normal key input
{
SendPlay %SaveKeyList% ; put captured text back in windows key buffer
}
else ; Now we have the input of the card reader
{
SplashTextOn, , , %SaveText% ; Do something with the input or the card reader ...
}
SaveKeyList=
SaveText=
SetTimer , SplashOff, 2000
return
SplashOff:
SplashTextOff
SetTimer , , Off
return
You can compile this script to a exe file (327KB) using the Autohotkey Compiler . 您可以使用Autohotkey编译器将此脚本编译为exe文件(327KB)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.