是德科技
直播中

王银喜

7年用户 2326经验值
私信 关注
[问答]

使用键盘箭头键移动电机舞台只有用鼠标点击切换按钮才能实现

您好,我想用键盘上的箭头按钮控制我的3轴电机舞台的运动。
(类似于几乎每个小型PC游戏,例如PC赛车游戏)。
到目前为止,只有用鼠标点击切换按钮才能实现。
有没有人知道如何通过按键盘上的按钮获得(直接)输入?
- 使用激活OK命令的F按钮(F1,F2,...)不是答案 - 键盘通过USB或PS / 2连接。
我找不到它作为I / O仪器(没有USB / TMC协议?)) - 我有更好的机会使用适配器(例如PS / 2到RS232)?
谢谢你的每一个提示!

以上来自于谷歌翻译


     以下为原文

  Hello,
I want to control the movement of my 3axis motor stage with the arrow buttons of my keyboard.
(similar to almost each small pc game, e.g. pc racing game).

Until now it is only possible by clicking on toggle-buttons with my mouse.

Does anyone know a possibility how to get a (direct) input by pressing a button on the keyboard?

    - the usage of F-buttons (F1,F2,...) which activate the OK-command is not the answer
    - Keyboard is connected via USB or PS/2. I cannot find it as an I/O Instrument (no USB/TMC-protocoll?))
    - would I have better chance by using an adapter (e.g. PS/2 to RS232)?

thanks for each hint!  

回帖(5)

顾天天

2018-9-28 16:47:02
我想我会尝试回复这个问题,因为它已经有一段时间没有得到答复:-(我认为这可以做到,但我还是说它需要用.NET控件来完成。
我会接近它是创建一个.NET面板,它是用户控件的基础,然后创建一个KeyPress事件。我尝试制作一个比我想象的更难的快速演示 - 做一个网络搜索似乎这个
是一个已知的问题,你需要调用Panel.Focus()(或你正在使用的任何控件 - 它可能是一个带有4向箭头的标签......)我发现我需要调用它
开始以及每次按下一个键(可能是焦点丢失到对话框中)。我确信这可以改进,但至少它说明我有可能发现一个字符键同时触发KeyPress和KeyDown
事件,而箭头键(或功能键)只被后者困住.HTH迈克

以上来自于谷歌翻译


     以下为原文

  I thought I'd make an attempt at a reply for this as it has been unanswered for some time :-(

I think this can be done, but I would also say that it needs to be done with a .NET control.  The way I would approach it is to create a .NET panel which is the basis of the user control and then create a KeyPress Event.  I tried making a quick demo which was a bit more difficult than I had thought - doing a web search it seems this is a known issue and that you need to call
Panel.Focus()
( or whatever control you're using - it could be a label with a 4-way arrow on it... )

I found I needed to call it at the start and also each time a key was pressed ( presumably the focus was lost to the dialog box ).  I'm sure this could be improved but at least it demostrates that it is possible

I also discovered that a character key triggered both KeyPress and KeyDown events, whereas an arrow key ( or a function key ) is only trapped by the latter.

HTH

Mike

附件

举报

王银喜

2018-9-28 17:02:28
引用: bgvywerq 发表于 2018-9-28 19:15
我想我会尝试回复这个问题,因为它已经有一段时间没有得到答复:-(我认为这可以做到,但我还是说它需要用.NET控件来完成。
我会接近它是创建一个.NET面板,它是用户控件的基础,然后创建一个KeyPress事件。我尝试制作一个比我想象的更难的快速演示 - 做一个网络搜索似乎这个
是一个已知的问题,你需要调用Panel.Focus()( ...

非常感谢您的回复。
你帮助了我很多,在你的帮助下,你可以通过keydown和keyup-event来控制事件。
不幸的是,我无法同时实现2个按钮的控制。
当容器被推到一起时,ControlContainer只接受其中一个,因此我只能将我的遥控设备向前/向后或向右/向左移动......你知道是否有可能解决这个问题
无论如何?
否则我将无法驾驶曲线:-)

以上来自于谷歌翻译


     以下为原文

  Thank you _very much_ for your reply. 

You helped me a lot and with your help it was possible to control the events with the keydown- and keyup-event. 

Unfortunately I haven't been able to implement the control of 2 buttons at the same time. The ControlContainer accept only one of them, when the bottons are pushed together and therefore I'm only able to move my remote-controlled device either foward/backward or right/left... Do you know if there is a possibility to solve this anyhow? Otherwise I'll not been able to drive through curves :-)
举报

顾天天

2018-9-28 17:20:08
引用: hgimtk 发表于 2018-9-28 19:31
非常感谢您的回复。
你帮助了我很多,在你的帮助下,你可以通过keydown和keyup-event来控制事件。
不幸的是,我无法同时实现2个按钮的控制。

感谢您的反馈:-)它将同时处理多个按键,但当然,当您按下第二个键时,程序需要能够运行,即不等待我的示例中的对话框。
我对我制作的原始程序(附件)做了一个相当难看的mod。
您需要跟踪正在按下哪些键,并可能使用KeyUp事件来确定它们何时被释放。
毫无疑问,你也想要阻止向后+向前或向左+向右。
我会用全局变量跟踪事物。
我的例子只查找DOWN然后LEFT:它按下时设置全局Down,然后,如果按下Left时为true,它会弹出一个对话框。
此刻,按下并释放DOWN然后按下LEFT将产生相同的效果,但希望它显示原理。
我注意到,在对话框弹出之前我需要按下LEFT一段时间:我假设这与我的程序有关,但如果不是,那可能是一件令人讨厌的事情。
HTH迈克

以上来自于谷歌翻译


     以下为原文

  Thanks for the feedback :-)

It will deal with more than one keypress at the same time but of course the program needs to be able to run when you are pressing the second key i.e. not waiting for a dialog box as in my example.

I have made a rather ugly mod to the original program I made ( attached ).  You'll need to track which keys are being pressed and probably use a KeyUp event to decide when they have been released.  You'll no doubt also want to prevent back+forward or left+right.  I would track things with a global variable.  My example only looks for DOWN then LEFT: it sets the global Down when that is pressed and then, if that is true when the Left is pressed, it pops up a dialog.  At the moment, pressing and releasing DOWN and then pressing LEFT would have the same effect but hopefully it shows the principle.

I note that I need to press LEFT for a little while before the dialog pops up: I'm assuming that is to do with my program but if not that could be a nasty thing to fix.

HTH

Mike

附件

举报

王银喜

2018-9-28 17:32:32
谢谢,这很好。
我会尽快为我的电机阶段实现这个代码,并告诉你这一切是怎么回事。
这将是令人兴奋的:-)最好的问候约翰内斯

以上来自于谷歌翻译


     以下为原文

  Thanks that's nice. I'll implement this code for my motor stage as soon as possible and will tell you how it all went. It's gonna be exciting :-)

best regards

Johannes
举报

更多回帖

发帖
×
20
完善资料,
赚取积分