CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

高手!!给个例程吧!!!!!

楼主ghyghost(爱国人士-许愿池里的希腊老石头)2002-05-18 20:22:03 在 Delphi / VCL组件开发及应用 提问

setkeyboardstate  
   
  问题点数:30、回复次数:3Top

1 楼lvloj()回复于 2002-05-18 20:35:53 得分 15

粘一贴:  
  soaringbird:  
  检测:    
  Var    
      ks:   TkeyBoardState;    
  begin    
    GetKeyboardState(ks);    
    if   (ks[VK_NUMLOCK]   =   1)   then    
        ShowMessage('Num   Lock   is   on.')    
    else    
        ShowMessage('Num   Lock   is   off.');    
    if   (ks[VK_CAPITAL]   =   1)   then    
        ShowMessage('Caps   Lock   is   on.')    
    else    
        ShowMessage('Caps   Lock   is   off.');    
  end;    
   
  切换:    
  keybd_event(   VK_NUMLOCK,   $45,   KEYEVENTF_EXTENDEDKEY   or   0,0   );    
    keybd_event(   VK_NUMLOCK,   $45,   KEYEVENTF_EXTENDEDKEY   or   KEYEVENTF_KEYUP,   0);    
    keybd_event(   VK_CAPITAL,   $45,   KEYEVENTF_EXTENDEDKEY   or   0,   0   );    
    keybd_event(   VK_CAPITAL,   $45,   KEYEVENTF_EXTENDEDKEY   or   KEYEVENTF_KEYUP,   0);    
  *******************************************  
  Question    
   
  How   to   control   caps   lock   key?    
   
  Answer    
   
  A:    
  In   Windows   enviroment,   you   can   look   at   the   keyboard   lights   values,   but   you   can't    
  set   it,   because   Windows   intercept   your   peek   in   the   memory   and   blocks   it   (I   tryed    
  under   Windows   95,   maybe   under   Windows   3.11   it   works).   However,   you   should   be   able    
  to   look   at   the   status.    
  Try   to   put   this   simple   code   in   a   function:    
  const    
        SCROLLLOCK   =   1;    
        NUMLOCK         =   2;    
        CAPSLOCK       =   4;    
  var    
        Status:     Byte;    
        PntK:         ^Byte;    
  begin    
            PntK   :=   Ptr($40,   $97);                 {directly   point   in   memory}    
            Status   :=   Byte(PntK^);                 {read   the   status}    
            if   (NUMLOCK   and   Status)   =   NUMLOCK   then         {if   NUM   LOCK   is   on}    
                    Status   :=   Status   and   (255   -   NUMLOCK)         {turn   it   off}    
            else    
                    Status   :=   Status   or   2;                         {turn   it   on}    
            Pntk^   :=   Status;                                 {poke   in   memory   (don't   works)}    
  end;    
   
  A:    
   
  I   use   this   procedures   to   turn   on   the   caps   lock   if   it   isn't   already   on   when    
  the   user   enters   my   DBloockup   combo.     This   gets   rid   of   the   nasty   problem    
  of   case-sensitive   indexes.    
  procedure   TMainForm.StudentLookupEnter(Sender:   TObject);    
  Var   Level   :   Integer;    
          KeyState   :   TKeyBoardState;    
  begin    
      {check   if   caps-lock   is   on   -   if   not   turn   it   on}    
      Level   :=   GetKeyState(VK_CAPITAL);    
      GetKeyboardState(KeyState);    
      CapsLockStatus   :=   KeyState;    
      If   Level   =   0   then    
          begin    
              KeyState[VK_CAPITAL]   :=   1;    
              setKeyboardState(KeyState);    
          end;    
  end;    
   
   
   
  Question    
   
  I   need   my   application   to   be   able   to   "stuff   keystrokes"   into   the   keyboard    
  buffer.    
  My   application   needs   to   be   able   to   do   this   while   minimzed   and   the    
  keystrokes   should   effect   the   active   Window   and   appear   "typed".    
   
  Answer    
  A:    
  {this   proc   interrogates   the   numlock   key   and   sets   the   state}    
  {according   to   the   value   of   bOn}    
  procedure   TIndexForm.ToggleNumLockKey(bOn:   Boolean);    
  var    
      KeyState   :   TKeyBoardState;    
  begin    
      GetKeyboardState(   KeyState   );    
      if   bOn   then   KeyState[VK_NUMLOCK]   :=   1    
            else   KeyState[VK_NUMLOCK]   :=   0;    
      SetKeyboardState(   KeyState   );    
  end;Top

2 楼torble(阿裕)回复于 2002-05-18 20:39:50 得分 14

var  
      vKeys:   TKeyBoardState;  
  Begin  
      GetkeyBoardState(vKeys);  
      vKeys[VK_CAPITAL]   :=   1;  
      vKeys[VK_NUMLOCK]   :=   1;  
      SetkeyBoardState(vKeys);  
  End;    
  Top

3 楼lizhenjia(暴雪)回复于 2002-05-18 20:43:56 得分 1

好贴子!Top

相关问题

  • 谁能给个简单的关于web service的例程?
  • 谁能给我一个例程 ,用ado的oledb访问sql server!
  • C++ Builder 开发DirectX 3D程序,能给个例程?
  • 高手给个体绘制(Volume Rendering/Voxel Rendering)C/C++例程!holeen@163.com
  • 请教!能否给一个stringGrid的例程,谢谢!
  • 哥们给找一个使用coolbar的示例程序
  • 可不可以给一个钩子的例程啊?
  • <thinking in c++>的一个例程
  • 给我一个 HelloWDM 可用的例程,我把所有的分都给你!
  • 谁能给我一个实现DLL中带有Form的CBC或Delphi例程?

关键词

  • keyeventf
  • extendedkey
  • vk
  • keybd
  • numlock
  • ks
  • showmessage
  • capital
  • lock
  • caps

得分解答快速导航

  • 帖主:ghyghost
  • lvloj
  • torble
  • lizhenjia

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo