紅外條碼掃瞄器的另類使用C 版

2021-08-23 14:58:17 字數 3246 閱讀 1580

3年前寫了一篇《usb口的紅外條形碼掃瞄器的另類使用》,不過相關**是vb編寫,在這幾年之間,有許多網友提出需要c#版的,起初還以為由vb修改c#應該很容易,最近研究了一下,發現c#和vb呼叫api的機制還是有所不同的,在遷移的過程中還是會遇到不少問題,所以我專門抽時間做了乙個基於c#的程式。

【目前的條形碼掃瞄器有點類似外接鍵盤(其實從訊息傳送上它就相當於乙個鍵盤),把輸入焦點定位到可輸入的控制項上,一掃瞄相應的條形碼資訊就輸入到文字框中去了,但是如果沒有輸入焦點,或另乙個不相干的程式獲得輸入焦點,那就有點亂套了。我想實現的是,不管什麼情況,只要掃瞄器一工作,我的程式就能自動啟用,並能獲得當前輸入的條形碼資訊。 實現思路:我用的是litele牌的usb口的紅外條形碼掃瞄器,仔細分析了一下,掃瞄成功後,以鍵盤按鍵訊息的形式把條形碼輸入資訊通知給系統。這樣通過鍵盤鉤子就可以方便的獲得該資訊了。但是,怎樣區分資訊是鍵盤還是條形碼輸入的哪?很簡單,條形碼掃瞄器在很短的時間內輸入了至少3個字元以上資訊,並且以「回車」作為結束字元,在這種思想指引下,很完美的實現了預定功能。】

vb相關的**請見:

barcodehook 類:

using system; using system.collections.generic; using system.text; using system.runtime.interopservices; using system.reflection; namespace readbadcode private struct eventmsg [dllimport("user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall)] private static extern int setwindowshookex(int idhook, hookproc lpfn, intptr hinstance, int threadid); [dllimport("user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall)] private static extern bool unhookwindowshookex(int idhook); [dllimport("user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall)] private static extern int callnexthookex(int idhook, int ncode, int32 wparam, intptr lparam); [dllimport("user32", entrypoint = "getkeynametext")] private static extern int getkeynametext(int lparam, stringbuilder lpbuffer, int nsize); [dllimport("user32", entrypoint = "getkeyboardstate")] private static extern int getkeyboardstate(byte pbkeystate); [dllimport("user32", entrypoint = "toascii")] private static extern bool toascii(int virtualkey, int scancode, byte lpkeystate, ref uint lpchar, int uflags); delegate int hookproc(int ncode, int32 wparam, intptr lparam); barcodes barcode = new barcodes(); int hkeyboardhook = 0; string strbarcode = ""; private int keyboardhookproc(int ncode, int32 wparam, intptr lparam) ); } else byte kbarray = new byte[256]; uint ukey = 0; getkeyboardstate(kbarray); if (toascii(barcode.virtkey, barcode.scancode, kbarray, ref ukey, 0)) if (datetime.now.subtract(barcode.time).totalmilliseconds > 50) else strbarcode += barcode.chr.tostring(); } barcode.time = datetime.now; if (barcodeevent != null) barcodeevent(barcode); //觸發事件 barcode.isvalid = false; } } return callnexthookex(hkeyboardhook, ncode, wparam, lparam); } // 安裝鉤子 public bool start() return (hkeyboardhook != 0); } // 解除安裝鉤子 public bool stop() return true; } } }

【注意】和vb程式不同,要想測試實際的效果,必須執行編譯後的exe檔案,在開發環境直接執行會沒有效果的。

Nmap掃瞄器的使用

如果你的web伺服器是錯誤的配置並以root來執行,象上例一樣,它將是黎明前的黑暗。apache執行在root下,是不安全的實踐,你可以通過把 etc indeed.conf中的auth服務登出來阻止ident請求,並重新啟動ident。另外也可用使用ipchains或你的最常用的防火牆,在網路邊界...

C 使用TWAIN協議進行掃瞄器操作

折騰兩台掃瞄器程式的修改,今天有空把程式中涉及到掃瞄器操作的 貼出來,供大家一起交流學習。1 public arraylist transferpictures 224 25掃瞄程式,如果掃瞄完成,則返回xferdone 27if rc twrc.xferdone 2832 33結束掃瞄 35if ...

使用scapy做掃瞄器的一些技巧

有些時候nmap的掃瞄很嘈雜會觸發主機或者網路的ips警報。那麼在進行掃瞄的時候乙個可行的選項是使用arp ping。下面讓我們來看下在乙個c段下使用命令nmap pr 192.168.0.0 24進行arp ping掃瞄的時的資料報分布情況。沒有很多arp的資料報,對吧?當namp進行埠掃瞄時也是...