一个关于键盘的问题

mafangsan 2000-06-30 11:04:00
请问如何在程序中锁定小键盘,也就是说无论NumLock灯亮或暗,小键盘只提供数字功能。给出思路或源代码,感激不尽,成功立马给分。
...全文
232 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
mafangsan 2000-06-30
  • 打赏
  • 举报
回复
to xxfeng

如果这样做,按下键盘上的左方向键,就也会执行这个代码,我想小键盘左边的方向键还是自己的功能。
liyang 2000-06-30
  • 打赏
  • 举报
回复
xxfeng,那当我按"<-"键时?...
xxfeng 2000-06-30
  • 打赏
  • 举报
回复
Use Api also can do it. But easy way is like this.

If KeyCode = 37 Then
uu = Text1.SelStart
ii = Text1.SelText
If uu > 0 Then
Text1 = Left$(Text1, uu) & "4" & Right(Text1, Len(Text1) - Len(ii) - uu)
Text1.SelStart = uu + 2
End If
End If
Un1 2000-06-30
  • 打赏
  • 举报
回复
写一个全局键盘hook
Chen_Lin 2000-06-30
  • 打赏
  • 举报
回复
-------------试试键盘Hook吧-----------------------
-------------以下在Bas中----------------------
public declare function callnexthookex lib "user32" (byval hhook as long, byval ncode as long, byval wparam as long, byval lparam as long) as long

public declare function unhookwindowshookex lib "user32" (byval hhook as long) as long

public declare function setwindowshookex lib "user32" alias "setwindowshookexa" (byval idhook as long, byval lpfn as long, byval hmod as long, byval dwthreadid as long) as long

public declare function postmessage lib "user32" alias "postmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, byval lparam as long) as long

public const wh_keyboard = 2

public const kbh_mask = &h20000000

public const wm_lbuttondown = &h201

public const wm_lbuttonup = &h202


global hhook as long


'keyboardproc 在 vb 应用动作前发生

public function keyboardproc(byval ncode as long, byval wparam as long, byval lparam as long) as long

if ncode >= 0 then

'处理你希望过滤的键

if wparam = asc("c") and (lparam and kbh_mask) <> 0 then

if (lparam and &hc0000000) = 0 then
keyboardproc = 1
end if
end if
end if
keyboardproc = callnexthookex(hhook, ncode, wparam, lparam)
end function

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧