Daniza

Block Numeric Keys

17 posts in this topic

#1 ·  Posted

Hello, can autoit help me block all numeric (numbers) send by my keyboard but it will not block the nubmer send by magnetic swiper?

I work on restaurant and we use Swipe card for our timekeeping. The problem is if they forgot there swipe card they manually input it on our bundyclock using keyboard, which is against company policy working with incomplete uniform (Swipe Card)

they can easily see the code in magnetic swiper just open a notepad and swipe it on magnetic swiper then code will input then they memorize the code so without the swipe card they can do it manually.

Thanks. More power to you guys :)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Oooo this could be fun... :) 

The answer in short is yes, totally possible.

Just depends how you want to do it and how detailed you want to get.

 

The first idea that comes to mind for me is setting those keys as a hotkey and telling them to do nothing.

However those keys then could really be used for nothing.  So maybe telling the script to only block the keys when the time keeping software is open to make it more targeted.

If users using notepad and copy/pasting is a problem, block notepad too! :) (and wordpad and others as needed)

Also dont forget about OSK (On Screen Keyboard) Etc.

Hard to determine how far you need/want to go and how clever your employees are (thats the fun in it for me lol)

 

I'll add a small example as an edit in a bit.

;#NoTrayIcon

HotKeySet("{ESC}", "_Override")
_SetKeys()
AdlibRegister("_UnallowedPrograms", "1500")

Global $sMgrPassword = "imtheboss"
Global $iToggle = ""
Global $sAnswer = ""

While 1
    Sleep(10)
WEnd

Func _Null()
    ;Nothing
    MsgBox(0, "", "Entry by Keyboard Disabled by Policy")
EndFunc ;_Null

Func _Override()
    $sAnswer = InputBox("", "Manager Password for Override", "", "*")
    If $sAnswer = $sMgrPassword Then
        $iToggle = MsgBox(1, "Keyboard Override", "Press OK to Enable Keyboard Blocking, Cancel to Disable")
        If $iToggle = 1 Then _SetKeys()
        If $iToggle = 2 Then _UnsetKeys()
    EndIf
EndFunc ;_Override

Func _SetKeys()
    HotKeySet("{NUMPAD0}", "_Null")
    HotKeySet("{NUMPAD1}", "_Null")
    HotKeySet("{NUMPAD2}", "_Null")
    HotKeySet("{NUMPAD3}", "_Null")
    HotKeySet("{NUMPAD4}", "_Null")
    HotKeySet("{NUMPAD5}", "_Null")
    HotKeySet("{NUMPAD6}", "_Null")
    HotKeySet("{NUMPAD7}", "_Null")
    HotKeySet("{NUMPAD8}", "_Null")
    HotKeySet("{NUMPAD9}", "_Null")
    HotKeySet("{1}", "_Null")
    HotKeySet("{2}", "_Null")
    HotKeySet("{3}", "_Null")
    HotKeySet("{4}", "_Null")
    HotKeySet("{5}", "_Null")
    HotKeySet("{6}", "_Null")
    HotKeySet("{7}", "_Null")
    HotKeySet("{8}", "_Null")
    HotKeySet("{9}", "_Null")
    HotKeySet("{0}", "_Null")
    AdlibRegister("_UnallowedPrograms", "1500")
EndFunc ;_SetKeys

Func _UnsetKeys()
    HotKeySet("{NUMPAD0}")
    HotKeySet("{NUMPAD1}")
    HotKeySet("{NUMPAD2}")
    HotKeySet("{NUMPAD3}")
    HotKeySet("{NUMPAD4}")
    HotKeySet("{NUMPAD5}")
    HotKeySet("{NUMPAD6}")
    HotKeySet("{NUMPAD7}")
    HotKeySet("{NUMPAD8}")
    HotKeySet("{NUMPAD9}")
    HotKeySet("{1}")
    HotKeySet("{2}")
    HotKeySet("{3}")
    HotKeySet("{4}")
    HotKeySet("{5}")
    HotKeySet("{6}")
    HotKeySet("{7}")
    HotKeySet("{8}")
    HotKeySet("{9}")
    HotKeySet("{0}")
    AdlibUnRegister("_UnallowedPrograms")
EndFunc ;_UnsetKeys

Func _UnallowedPrograms()
    If ProcessExists("notepad.exe") Then ProcessClose("Notepad.exe")
EndFunc ;_UnallowedPrograms

 

Edited by ViciousXUSMC

Share this post


Link to post
Share on other sites

#3 ·  Posted

You might use a keyboard hook -  the same which was used in the former BlockInputEx  udf  :)

#include <Constants.au3>
#include <WinAPI.au3>

HotKeySet("{esc}", "_Exit")

Global $pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
Global $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _WinAPI_GetModuleHandle(0), 0)

While 1
   Sleep(10)
WEnd

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    Local $KBDLLHOOKSTRUCT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam)
    Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, "vkCode")
    Switch $vkCode
        Case 0x30 to 0x39, 0x60 to 0x69    ; number keys & numeric pad keys
                Return 1
    EndSwitch
     _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

Func _Exit()
    DllCallbackFree($pStub_KeyProc)
    _WinAPI_UnhookWindowsHookEx($hHook)
   Exit
EndFunc

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

You can include <WinAPIvkeysConstants.au3> in order to avoid magic numbers.

Case $VK_0 to $VK_9, $VK_NUMPAD0 to $VK_NUMPAD9

 

Saludos

 

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

If the number keys (or any keys) aren't needed, Google KeyTweak for a free utility that allows you to render them inactive.

Edited by aleph01

Meds.  They're not just for breakfast anymore. :'(

Share this post


Link to post
Share on other sites

#6 ·  Posted

12 minutes ago, Danyfirex said:

You can include <WinAPIvkeysConstants.au3> in order to avoid magic numbers.

So shouldn't this be done for use with the well-known _IsPressed  func ?  :)

Share this post


Link to post
Share on other sites

#7 ·  Posted

perhaps these ways also will block data from the "magnetic swiper"


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#8 ·  Posted

On ‎4‎/‎18‎/‎2017 at 4:53 PM, mikell said:

So shouldn't this be done for use with the well-known _IsPressed  func ?

It should be, but the _IsPressed function won't accept the VK key code variables, it requires them as a string, then adds the VK_ value to the code sent to it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#9 ·  Posted

I work with POS systems - AFAIK the magswipe is treated by windows as a keyboard - but I'd love to hear the results of this.  Will flag this and I may have to try it myself for a fun exercise.

Share this post


Link to post
Share on other sites

#10 ·  Posted

5 hours ago, BrewManNH said:

It should be, but the _IsPressed function won't accept the VK key code variables

The change in the udf would be tiny and cause no script break  :)

#include <WinAPIvkeysConstants.au3>  ; this could be included in Misc.au3

While 1
  If _IsPressed($VK_LBUTTON) Then Msgbox(0,"", "LButton pressed")
 ; If _IsPressed("01") Then Msgbox(0,"", "LButton pressed")
Wend

Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
    If StringLen($sHexKey) = 2 Then $sHexKey = '0x' & $sHexKey
    Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", $sHexKey)
    If @error Then Return SetError(@error, @extended, False)
    Return BitAND($a_R[0], 0x8000) <> 0
EndFunc   ;==>_IsPressed

btw if the magswipe is blocked too using the hook  then the Rawinput way could work

Share this post


Link to post
Share on other sites

#11 ·  Posted

BTW, nearly every barcode reader and mag reader I've run into acts as a keyboard input device of some kind. So blocking the numbers from the keyboard would probably block it from the mag reader as well depending on how its driver works.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#12 ·  Posted

Daniza,

What is the name of the Time Keeping system?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#13 ·  Posted

12 hours ago, kylomas said:

Daniza,

What is the name of the Time Keeping system?

kylomas

TMS Bundy Clock, :)

Share this post


Link to post
Share on other sites

#14 ·  Posted

20 hours ago, BrewManNH said:

BTW, nearly every barcode reader and mag reader I've run into acts as a keyboard input device of some kind. So blocking the numbers from the keyboard would probably block it from the mag reader as well depending on how its driver works.

Yes, it might be because application like Keytweak blocks input from the mag reader.

Share this post


Link to post
Share on other sites

#15 ·  Posted

On 4/19/2017 at 4:44 AM, aleph01 said:

If the number keys (or any keys) aren't needed, Google KeyTweak for a free utility that allows you to render them inactive.

Thanks for suggestion, i Try this before i post here but it blocks the Numeric inputs came from magnetic card reader :)

Share this post


Link to post
Share on other sites

#16 ·  Posted

On 4/18/2017 at 10:59 PM, ViciousXUSMC said:

Oooo this could be fun... :) 

The answer in short is yes, totally possible.

Just depends how you want to do it and how detailed you want to get.

 

The first idea that comes to mind for me is setting those keys as a hotkey and telling them to do nothing.

However those keys then could really be used for nothing.  So maybe telling the script to only block the keys when the time keeping software is open to make it more targeted.

If users using notepad and copy/pasting is a problem, block notepad too! :) (and wordpad and others as needed)

Also dont forget about OSK (On Screen Keyboard) Etc.

Hard to determine how far you need/want to go and how clever your employees are (thats the fun in it for me lol)

 

I'll add a small example as an edit in a bit.

;#NoTrayIcon

HotKeySet("{ESC}", "_Override")
_SetKeys()
AdlibRegister("_UnallowedPrograms", "1500")

Global $sMgrPassword = "imtheboss"
Global $iToggle = ""
Global $sAnswer = ""

While 1
    Sleep(10)
WEnd

Func _Null()
    ;Nothing
    MsgBox(0, "", "Entry by Keyboard Disabled by Policy")
EndFunc ;_Null

Func _Override()
    $sAnswer = InputBox("", "Manager Password for Override", "", "*")
    If $sAnswer = $sMgrPassword Then
        $iToggle = MsgBox(1, "Keyboard Override", "Press OK to Enable Keyboard Blocking, Cancel to Disable")
        If $iToggle = 1 Then _SetKeys()
        If $iToggle = 2 Then _UnsetKeys()
    EndIf
EndFunc ;_Override

Func _SetKeys()
    HotKeySet("{NUMPAD0}", "_Null")
    HotKeySet("{NUMPAD1}", "_Null")
    HotKeySet("{NUMPAD2}", "_Null")
    HotKeySet("{NUMPAD3}", "_Null")
    HotKeySet("{NUMPAD4}", "_Null")
    HotKeySet("{NUMPAD5}", "_Null")
    HotKeySet("{NUMPAD6}", "_Null")
    HotKeySet("{NUMPAD7}", "_Null")
    HotKeySet("{NUMPAD8}", "_Null")
    HotKeySet("{NUMPAD9}", "_Null")
    HotKeySet("{1}", "_Null")
    HotKeySet("{2}", "_Null")
    HotKeySet("{3}", "_Null")
    HotKeySet("{4}", "_Null")
    HotKeySet("{5}", "_Null")
    HotKeySet("{6}", "_Null")
    HotKeySet("{7}", "_Null")
    HotKeySet("{8}", "_Null")
    HotKeySet("{9}", "_Null")
    HotKeySet("{0}", "_Null")
    AdlibRegister("_UnallowedPrograms", "1500")
EndFunc ;_SetKeys

Func _UnsetKeys()
    HotKeySet("{NUMPAD0}")
    HotKeySet("{NUMPAD1}")
    HotKeySet("{NUMPAD2}")
    HotKeySet("{NUMPAD3}")
    HotKeySet("{NUMPAD4}")
    HotKeySet("{NUMPAD5}")
    HotKeySet("{NUMPAD6}")
    HotKeySet("{NUMPAD7}")
    HotKeySet("{NUMPAD8}")
    HotKeySet("{NUMPAD9}")
    HotKeySet("{1}")
    HotKeySet("{2}")
    HotKeySet("{3}")
    HotKeySet("{4}")
    HotKeySet("{5}")
    HotKeySet("{6}")
    HotKeySet("{7}")
    HotKeySet("{8}")
    HotKeySet("{9}")
    HotKeySet("{0}")
    AdlibUnRegister("_UnallowedPrograms")
EndFunc ;_UnsetKeys

Func _UnallowedPrograms()
    If ProcessExists("notepad.exe") Then ProcessClose("Notepad.exe")
EndFunc ;_UnallowedPrograms

 

I will try this one if it will not block the Numeric keys send by magnetic reader.

Share this post


Link to post
Share on other sites

#17 ·  Posted

On 4/23/2017 at 8:40 AM, Daniza said:

I will try this one if it will not block the Numeric keys send by magnetic reader.

It probably will if the reader is a HID Keyboard Device. 

Time to get a keyboard with no numbers on it :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now