I don't think that you can do that programatically. Barcode scanner "emulates" a keyboard. Moreover, it is *usually* plugged into the same cable port as the keyboard. So, it doesn't matter what the input is - keyboard or scanner - the result is the same.

Therefore, you'll need to do something "physically" - lock the keyboard into a box, take keys out of the keyboard, hide it behind the wall ... whatever.

I've seen a complex solution to this (don't have the code sorry)
where timers where used to detect input
if input in a field is done then the time to fill this field is calculated, if time < certain value then input was scanner else keyboard and raise form_trigger_failure