Capturing a Key press

polonious
polonious Member Posts: 64
Hi,

I have a text field that I would like to prevent typing/pasting into, but allow a scanner to scan a barcode into it. Is there a way I can tell if a key on the keyboard has been pressed so I can error out and prevent it, but if the user scans a barcode the barcode will appear in the text box?

Thanks.

Comments

  • Savatage
    Savatage Member Posts: 7,142
    interesting.. but I think a scanner "Y"ed into the keyboard port simply acts as a keyboard.
    simply making the entry of the number or code easier.

    My vote would lean towards no, but maybe someone else has a diff view?
  • polonious
    polonious Member Posts: 64
    Hopefully! It's a tricky one!
  • matttrax
    matttrax Member Posts: 2,309
    Don't know the specifics of your program, so just throwing out ideas.

    In the OnInputChange trigger you could use SendKeys to send a TAB. Technically if the user really wanted to change it they still could. Also wouldn't work if the device sent one key press at a time.

    Could you have another field / global variable that the device fills in? This field wouldn't be displayed on the form, and the real field would not be editable.

    A shortcut key on the form that starts up "Scan Mode" so that it knows the next input it receives goes to that field.

    Who knows, none of them probably work, but brainstorming is fun :P
  • Tomas
    Tomas Member Posts: 420
    polonious wrote:
    Hi,

    I have a text field that I would like to prevent typing/pasting into, but allow a scanner to scan a barcode into it. Is there a way I can tell if a key on the keyboard has been pressed so I can error out and prevent it, but if the user scans a barcode the barcode will appear in the text box?

    Thanks.

    Why would you want to prevent this? There are quite a lot of scenarios when for some strange reason scanners might not work (cold environments, bad bar code quality/design/colours) and then user will be forced to enter details manually.
  • polonious
    polonious Member Posts: 64
    Cheers fella's...

    matttrax - you might be on to something there with the hidden field and scan button, might look into that further, cheers.

    Tomas - yeh valid points mate, but this is a password field for which all users have a staff card with the password barcoded onto it. Problem is, some were clever enough to scan their card into notepad and are now sharing their passwords with others. So thats all going to be disabled now, but I also want to stop them from typing into that field altogether just in case.
  • Tomas
    Tomas Member Posts: 420
    polonious wrote:
    Problem is, some were clever enough to scan their card into notepad and are now sharing their passwords with others.

    hehe, hey at least, you have bright people working in the company :)
  • Alex_Chow
    Alex_Chow Member Posts: 5,063
    You can do a timer on the field. So if the next character is not entered within 0.0001 seconds, make the field not editable.

    Don't know if this would work though, never tried it.
  • DenSter
    DenSter Member Posts: 8,307
    Not a bad idea, but impossible to troubleshoot. You want to try to debug a form that fires a timer event every 1/1000 of a second? I wonder what happens to the computer's performance, CPU usage would probably go through the roof.
  • KYDutchie
    KYDutchie Member Posts: 345
    Hi,

    Would it be possible to add a special character to the beginning of barcode.
    This way when the user starts entering information through the keyboard, you can scan for that character to be entered first and if it is not correct, error out.

    It is not completely fireproof, but hey it is an idea,

    have fun,

    regards,

    Willy
    Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
  • Savatage
    Savatage Member Posts: 7,142
    That's an Idea..what if your scan card had a leading char that doesn't exist on normal keyboards.

    :-k
  • Alex_Chow
    Alex_Chow Member Posts: 5,063
    1. Scan onto the notepad
    2. Copy and paste to the field

    broken... :(
  • Savatage
    Savatage Member Posts: 7,142
    edited 2009-03-04
    =D> Arrgh! :mrgreen: Delete nopepad & wordpad & all Pads!!!!! :^o Just kidding

    he does mention something about covering that part..
    scan their card into notepad and are now sharing their passwords with others. So thats all going to be disabled now

    Isn't there a post somewhere about not allowing pasting?
  • Alex_Chow
    Alex_Chow Member Posts: 5,063
    Or if it's possible to change the solution to be login based instead of password based...
  • themave
    themave Member Posts: 1,058
    polonious wrote:
    Cheers fella's...

    matttrax - you might be on to something there with the hidden field and scan button, might look into that further, cheers.

    Tomas - yeh valid points mate, but this is a password field for which all users have a staff card with the password barcoded onto it. Problem is, some were clever enough to scan their card into notepad and are now sharing their passwords with others. So thats all going to be disabled now, but I also want to stop them from typing into that field altogether just in case.
    Move to thumbprint readers, that would fix it. Just half joking
  • polonious
    polonious Member Posts: 64
    Yeh notepad/wordpad etc. will be gone so that won't be a problem. However with 350+ staff cards already issued, not sure the business will want to reprint them all with changed passwords (i.e with special leading characters!)!

    Thumbreaders! nice idea!
  • polonious
    polonious Member Posts: 64
    Right, so I'm going to give Alex Chow's idea a go. I'm going to start a timer when the first key is pressed, then within half a second or so it will try validating the password. It will give enough time for the scanner to work, but not enough time for the user to type the password. I hope!!!
  • polonious
    polonious Member Posts: 64
    Result!

    For anyone interested... By using the OnInputChange() and OnAfterInput() triggers on the text field, I am capturing the length of time it takes for the user to enter the password. OnInputChange() starts the timer, and then OnAfterInput() stops the timer, giving me the elapsed time. If it takes longer than half a second, it's erroring out, otherwise it will login as usual. This gives enough time for the scanner to scan the password, but not enough time to type it in (no matter how good your touch-typing is!!!).

    Thanks for the assistance lads!
  • DenSter
    DenSter Member Posts: 8,307
    Users could still paste it in though right? Type the password in notepad, copy it, paste it into the field in NAV.
  • polonious
    polonious Member Posts: 64
    Nope! See my post from earlier, Notepad/Wordpad etc are all disabled on the machines...
  • DenSter
    DenSter Member Posts: 8,307
    Cool, that's a pretty smart solution actually.
  • Savatage
    Savatage Member Posts: 7,142
    polonious wrote:
    Nope! See my post from earlier, Notepad/Wordpad etc are all disabled on the machines...

    do the machines have email? copy paste can be done with many profgrams not just Notepad & Word Pad
  • polonious
    polonious Member Posts: 64
    Nope, the only running program is Navision. Everything else is either disabled or uninstalled.
  • Alex_Chow
    Alex_Chow Member Posts: 5,063
    Love it! I'm sure if the user really tries, he/she will find ways around it, but this will definately prevent a majority of the people from entering other people's PW.
  • themave
    themave Member Posts: 1,058
    Alex Chow wrote:
    Love it! I'm sure if the user really tries, he/she will find ways around it, but this will definately prevent a majority of the people from entering other people's PW.
    agree you found a programming solution to a people problem. In my company, if employee was trading passwords to get access to info they shouldn't have, I couldn't trust them and they would be terminated. With the current job market, I am pretty confident I could find an honest replacement
  • ara3n
    ara3n Member Posts: 9,258
    polonious wrote:
    Nope, the only running program is Navision. Everything else is either disabled or uninstalled.

    The user can hit F1 and use the search box to copy and paste.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3n
    ara3n Member Posts: 9,258
    The can use file database Open Text box to do copy and paste.

    They can click on Start Run and use copy and paste.

    They can do Ctrl+F and use the find dialog to copy and paste.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DenSter
    DenSter Member Posts: 8,307
    Or open any other NAV form for that matter :-k
  • ara3n
    ara3n Member Posts: 9,258
    what you need is an automation that has an event for a card reader. You cannot use wedge card reader.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n