下面三个测试都是一样的,给你参考一下。procedure TForm1.Button1Click(Sender: TObject);type vkalphabet = (a = $41, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z); vknumeral = (vk0 = $30, vk1, vk2, vk3, vk4, vk5, vk6, vk7, vk8, vk9);var alphabet: vkalphabet; umeral: vknumeral;begin Memo1.SetFocus; for alphabet := a to z do begin keybd_event(integer(alphabet), MapVirtualKey(integer(alphabet), 0), 0, 0); keybd_event(integer(alphabet), MapVirtualKey(integer(alphabet), 0), KEYEVENTF_KEYUP, 0); end; for umeral := vk0 to vk9 do begin keybd_event(integer(umeral), MapVirtualKey(integer(umeral), 0), 0, 0); keybd_event(integer(umeral), MapVirtualKey(integer(umeral), 0), KEYEVENTF_KEYUP, 0); end;end;procedure TForm1.Button2Click(Sender: TObject);var c: Char;begin Memo1.SetFocus; for c := '0' to '9' do begin keybd_event(Ord(c), MapVirtualKey(Ord(c), 0), 0, 0); keybd_event(Ord(c), MapVirtualKey(Ord(c), 0), KEYEVENTF_KEYUP, 0); end; for c := 'A' to 'Z' do begin keybd_event(Ord(c), MapVirtualKey(Ord(c), 0), 0, 0); keybd_event(Ord(c), MapVirtualKey(Ord(c), 0), KEYEVENTF_KEYUP, 0); end;end;procedure TForm1.Button3Click(Sender: TObject);var c: integer;begin Memo1.SetFocus; for c := $41 to $41 + 25 do begin keybd_event(c, MapVirtualKey(c, 0), 0, 0); keybd_event(c, MapVirtualKey(c, 0), KEYEVENTF_KEYUP, 0); end; keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), 0, 0); //shift键按下 for c := $41 to $41 + 25 do begin keybd_event(c, MapVirtualKey(c, 0), 0, 0); keybd_event(c, MapVirtualKey(c, 0), KEYEVENTF_KEYUP, 0); end; keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), KEYEVENTF_KEYUP, 0); //shift键弹起 for c := $30 to $30 + 9 do begin keybd_event(c, MapVirtualKey(c, 0), 0, 0); keybd_event(c, MapVirtualKey(c, 0), KEYEVENTF_KEYUP, 0); end;end;