[英]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.