[英]How to simulate keyboard keys in unity?
我目前正在我的研究生项目中工作,它是自动驾驶仪,我正在统一制作飞机,所有机器学习内容都在python中,python代码将仅返回飞机将进行的“上,下,左,右,引擎动力” ,...),而c#代码将处理所有物理问题,依此类推,因此我想模拟一下,如果(向左),计算机将按(A)。
我已经尝试过inputsimulator,仅此而已。
string t = GUIUtility.systemCopyBuffer; // this will get the input from python
if (t=="left") // if what the neural network choose is left do this
{
//what I need to convert the "left" to an actual keyboard press to
//be used by the crossplatformmanager
}
float roll = CrossPlatformInputManager.GetAxis("Horizontal");
我希望:
if (t=="left")
{
keyboardbutton="A"
}
并且那个CrossPlatformInputManager.GetAxis
将把它当作我实际按下该键一样。
我认为这是一个XY问题,通常对于无法控制的程序需要输入仿真,因为您无法直接访问代码。 但是对于您的问题,python和unity项目都是由您自己编写的,因此您无需模拟输入,只需调用该方法即可。
例如,如果您想通过水平轴输入来滚动某物,则可以这样做:
var h = Input.GetAxis("Horizontal");
Roll(h);
然后,如果该值来自剪贴板:
float h;
string t = GUIUtility.systemCopyBuffer;
switch(t) {
case "left": h = -1f; break;
case "right": h = 1f; break;
....
}
Roll(h);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.