欢迎光临
我们一直在努力

如何识别键盘左右的shift,Ctrl或Alt键-.NET教程,评论及其它

建站超值云服务器,限时71元/月

用api (getasynckeystate)实现,在win 2k,xp 下有效:

private declare function getasynckeystate lib "user32" (byval vkey as long) as integer

private const vk_lshift = &ha0

private const vk_rshift = &ha1

private const vk_lctrl = &ha2

private const vk_rctrl = &ha3

private const vk_lmenu = &ha4

private const vk_rmenu = &ha5

private sub form_keydown(keycode as integer, shift as integer)

if keycode = vbkeyshift and shift = vbshiftmask and (getasynckeystate(vk_lshift) and &h8000) then msgbox "you click the left shift"

if keycode = vbkeyshift and shift = vbshiftmask and (getasynckeystate(vk_rshift) and &h8000) then msgbox "you click the right shift"

if keycode = vbkeymenu and shift = vbaltmask and (getasynckeystate(vk_lmenu) and &h8000) then msgbox "you click the left alt" only alt was pressed

if keycode = vbkeymenu and shift = vbaltmask and (getasynckeystate(vk_rmenu) and &h8000) then msgbox "you click the right alt" only alt was pressed

if keycode = vbkeycontrol and shift = vbctrlmask and (getasynckeystate(vk_lctrl) and &h8000) then msgbox "you click the left ctrl"

if keycode = vbkeycontrol and shift = vbctrlmask and (getasynckeystate(vk_rctrl) and &h8000) then msgbox "you click the right ctrl"

end sub

private sub form_load()

me.keypreview = true

end sub

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何识别键盘左右的shift,Ctrl或Alt键-.NET教程,评论及其它
分享到: 更多 (0)

相关推荐

  • 暂无文章