另一种方法:<br><br>procedure SetCapsLock(on: boolean); <br>begin <br> if on = (GetKeyState(VK_CAPITAL) = 0) then <br> begin <br> keybd_event(VK_CAPITAL, MapVirtualKey(VK_CAPITAL, 0), 0, 0); <br> keybd_event(VK_CAPITAL, MapVirtualKey(VK_CAPITAL, 0), KEYEVENTF_KEYUP, 0); <br> end; <br>end; <br> <br>procedure SetNumLock(on: boolean); <br>begin <br> if on = (GetKeyState(VK_CAPITAL) = 0) then <br> begin <br> keybd_event(VK_NUMLOCK, MapVirtualKey(VK_NUMLOCK, 0), <br> KEYEVENTF_EXTENDEDKEY, 0); <br> keybd_event(VK_NUMLOCK, MapVirtualKey(VK_NUMLOCK, 0), <br> KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0); <br> ShowMessage('ok'); <br> end; <br>end; <br> <br>procedure SetScroll(on: boolean); <br>begin <br> if on = (GetKeyState(VK_SCROLL) = 0) then <br> begin <br> keybd_event(VK_SCROLL, MapVirtualKey(VK_SCROLL, 0), 0, 0); <br> keybd_event(VK_SCROLL, MapVirtualKey(VK_SCROLL, 0), KEYEVENTF_KEYUP, 0); <br> end; <br>end; <br> <br>其中,numlock 应该跟其他一样,但我发现,灯并不变, <br>只有在用了 ShowMessage 以后才会正确变化, <br>谁能说说吗?