用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
