自定义按键事件 [英] Custom Key press event

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

问题描述

我正在尝试允许用户提供自己的按键组合来触发事件.
例如,将允许用户在文本框中提供键的组合.一旦按下了组合键,就会发生一些事件(关闭form2或类似的东西).

I am trying to allow users to give their own combination of keys to trigger an event.
For example, the user will be allowed to give a combination of keys in a textbox. And once the combination of keys are pressed some event should occur(close form2 or something like that).

现在第1部分是:-应该允许用户在提供的文本框中输入他们的键组合(shift + control + z).

Now part 1 is:- The user should be allowed to give their combination of key in the textbox provided(shift+control+z).

第2部分:一旦用户单击组合键(在文本框中指定),就应该发生一个事件.

Part 2: Once the user clicks the combination of keys(which was specified in the textbox) an event should occur.

我一直试图做到这一点,但被卡住了.因此,我们将不胜感激.

I have been trying to get this done but got stuck. So any help will be appreciated.

推荐答案

Dim Shift As Boolean = False
Dim Ctrl As Boolean = False
Dim Z As Boolean = False

If e.KeyCode = Keys.Shift Then
Shift = True
ElseIf e.KeyCode = Keys.Control Then
Control = True
ElseIf e.KeyCode = Keys.Control Then
Z = True
'DO WHATEVER COMMAND BELOW
'EXAMPLE:
Form2.Close
Shift = False
Ctrl = False
Z = False
End If

这应该采用keydown事件的形式.

This should be in the form keydown event.


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

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