键盘事件按键 [英] keyboard event keypress

查看:99
本文介绍了键盘事件按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我已经为rhinoceros做了一个插件。现在我的问题是,在我的一个表单中,我想通过在点击a或s时添加一个double来为某些变量赋予不同的值keyboard.i尝试使用我的形式的事件,如按键和犀牛事件的键盘键盘,但我不明白为什么它不总是工作。有时它运行有时它不。我试图再次调用它,如果形成失去焦点或gotfocus但没有结果。然后另一个问题是,通过使用键盘它在rhinocommand线上,我不想要,但我不知道任何功能,以避免它。任何建议?我尝试globalKeyboardHook但它给我一个回调错误。

现在我不知道我是否必须使用keypress事件来处理我的表格或其他所有控件。我希望不要太神秘。谢谢。我做过的一个例子。我认为这很容易......



dblvariable = 0;



private void myform_KeyPres s(对象发送者,KeyPressEventArgs e)

{

if(e.KeyChar.ToString()==a)

{

dblvariable = dblvariable + 0.05;

}

}

Hi all.i have done a plug in for rhinoceros.now my problem is that in one of my forms i would like to give a different value to some variables by adding a double while clicking "a" or "s" on the keyboard.i tried using the events of my form like keypress and and the event of rhinoceros for keyboardkeypress but i can't understand why it is not always working.sometimes it runs sometimes it does not.i tried to call it again if the form lost focus or gotfocus but no result.then another problem is that by using keyboard it writs on rhinocommand line,and i don't want,but i don't know any function to avoid it.any suggestion?i tried globalKeyboardHook but it gives me a callback error.
now i don't know if i have to use the keypress event for all controls in my forms or other.i hope not to be too mysterious.thanks.here there is an example of wath i have done.i thought it would be easy...

dblvariable=0;

private void myform_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar.ToString() == "a")
{
dblvariable=dblvariable+0.05;
}
}

推荐答案

也许你应该去 Control.KeyDown [ ^ ]事件,当控件具有焦点时按下键时发生



例如,

Maybe you should go for Control.KeyDown[^] event which occurs when a key is pressed while the control has focus.

For example,
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.A)
    {
        MessageBox.Show("A pressed.");
    }

    if (e.KeyCode == Keys.S)
    {
        MessageBox.Show("S pressed.");
    }
}





-KR



-KR


这篇关于键盘事件按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆