如何让VB程序在后台接受键盘输入 给你说个简单好用的办法把'1添加一个Timer时间控件Private Declare Function GetAsyncKeyState Lib\"user32\"(ByVal vkey As Long)As Integer'申明apiPrivate Function MyHotKey(vKeyCode)As BooleanMyHotKey=((GetAsyncKeyState(vKeyCode)))End FunctionPrivate Sub Form_Load()Timer1.Interval=100 '定时检测Me.Visible=FalseEnd SubPrivate Sub Timer1_Timer()If MyHotKey(vbKeyO)Then Me.Visible=True'还可以换成调用其他函数End Sub
vb.net 获取键盘输入的字符 参考方法如下,具体解释已经注解在代码中;定义变量public delegate int HookProc(int nCode,Int32 wParam,IntPtr lParam);static int hKeyboardHook=0;HookProc KeyboardHookProcedure;声明API函数安装钩子(using System.Runtime.InteropServices;[DllImport(\"user32.dll\",CharSet=CharSet.Auto,CallingC.StdCall)]public static extern int SetWindowsHookEx(int idHook,HookProc lpfn,IntPtr hInstance,int threadId);卸载钩子[DllImport(\"user32.dll\",CharSet=CharSet.Auto,CallingC.StdCall)]public static extern bool UnhookWindowsHookEx(int idHook);继续下一个钩子[DllImport(\"user32.dll\",CharSet=CharSet.Auto,CallingC.StdCall)]public static extern int CallNextHookEx(int idHook,int nCode,Int32 wParam,IntPtr lParam);取得当前线程编号(线程钩子需要用到)[DllImport(\"kernel32.dll\")]static extern int GetCurrentThreadId();钩子子程:就是钩子所要做的事情private int KeyboardHookProc(int nCode,Int32 wParam,IntPtr lParam){if(nCode>;=0){线程键盘钩子判断是否按下键Keys keyData=(Keys)wParam;if(lParam.ToInt32()>;0){。
VB能区分键盘输入和扫描器输入吗? 具体怎么做? 现在常规的扫描码也是模拟键盘输入的,应该说不能区分.除非你选用串口的扫描器,这样自然就分开了.