1.  PostMessage(Form1.Edit1.Handle, WM_CHAR, 65, 0);
2.  scan code : A code number transmitted to a computer whenever a key is pressed or released. Each key on the keyboard has a unique scan code. This code is not the same as the ASCII code for the letter, number, or symbol shown on the key; it is a special identifier for the key itself and is always the same for a particular key. When a key is pressed, the scan code is transmitted to the computer, where a portion of the read-only memory basic input/output system (ROM BIOS) dedicated to the keyboard translates the scan code into its ASCII equivalent. Because a single key can generate more than one character—lowercase "a" and uppercase "A," for example—the ROM BIOS also keeps track of the status of keys that change the keyboard state, such as the SHIFT key, and takes them into account when translating a scan code. 
VK 是一个Windows的设备无关性键值,在Windows单元定义

解决方案 »

  1.   

    Thanks zkfly first.
    我的问题是:有六个编辑框,需要随时切换焦点,是否可以直接发键盘消息给窗口,哪个编辑框有焦点就在哪里显示,而不使用编辑框的句柄,这样用PostMessage 可以做到吗?
    如果用keybd_event,怎样发送大写或换档字符,谁能详细说明一下。
      

  2.   

    是否要用SetKeyboardState 函数?
      

  3.   

    我不管啦,谁告诉我用keybd_event 怎么发 ':'这个字符,其他不要了。
      

  4.   

    用keybd_event 先把shift(16)按下,在按";"(186),在让shift弹开即可
    1 keybd_event(16,16,0,0);
    2 keybd_event(186,186,0,0);
    3(弹开略去)
      

  5.   

    Anoa: Thank you ^_^.再一个问题,这些键值(16、186)是怎么得来的?我怎么找不到。
      

  6.   

    最好是查一下MSDN了Virtual-Key Codes,或者查一下Delphi自带的Api帮助。
    哦,Anoa,如果Shift键不放的话会有问题吧,那今后的按键不是Shift一直按着吗?
    以小弟之见还是弹开的好,在最后加上keybd_event(16,0,KEYEVENTF_KEYUP,0)
      

  7.   

    刚才我马上试了一下,按键弹起我已经搞定了。
    MSDN 里面好象只有名称没有数值,Delphi 的封装又不全,Windows.pas 里的定义缺了好多。
    Anoa 是在那里找到的?
      

  8.   

    在form的onkeydown事件里面,key(:word)值就是
      

  9.   

    to zkfly:
     当然弹开的好呢,不然就麻烦了:))
      

  10.   

    to Anoa:
     你不觉得windows.pas 里的定义不全吗?象, . / ' ; ` - = \ 这些键值我都找不到。里面的键值从165 直接跳到229,186 在哪里呢?
    再帮忙一下。
      

  11.   

    不好意思,刚才我没理解Anoa 的意思,现在明白了。多谢!