如何识别键盘左右的shift,Ctrl或Alt键
用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[来源www.iocblog.net]
文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。