Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Disable keyboard input in Barcode textbox
Message
From
05/05/2019 16:48:54
 
 
To
05/05/2019 14:00:18
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01668357
Message ID:
01668405
Views:
51
>Dear Sir Tore Bleken and Rick Hodgin
>
>I was satisfied with my short solution but suddenly I shocked when an end user wrote something in notepad. Copy that code and paste into scanner textbox.
>
>Then my codes got failure. It is my badluck.
>Do not know how to restrict users to copy paste in this textbox.
>
>So I need your more help in this regard.
>
>Please

Tariq,

Inhibit Ctrl+V when the control gets focus, reinstate it when it lose focus.

This is the ScannerBox class as I suggested in Tek-Tips, in response to a comment from another forum member, with the added Paste inhibition. It's a pity that you're not willing to face the challenge to move it into a Visual class, which is quite simple, actually.
LOCAL Test AS TestForm

m.Test = CREATEOBJECT("TestForm")
m.Test.Show(1)

DEFINE CLASS TestForm AS Form

	ADD OBJECT lblRegular AS Label WITH Caption = "Regular", Top = 10, Autosize = .T.
	ADD OBJECT Regular AS TextBox WITH Top = 10, Left = 100
	ADD OBJECT lblScanner AS Label WITH Caption = "Scanner", Top = 40, Autosize = .T.
	ADD OBJECT Scanner AS ScannerBox WITH Top = 40, Left = 100

	ADD OBJECT Simulator AS CommandButton WITH Top = 80, Caption = "Simulate Scanner", Autosize = .T.
	ADD OBJECT CtrlC AS CommandButton WITH Top = 120, Caption = "Ctrl+C 0123456789{ENTER}", Autosize = .T.

	PROCEDURE Simulator.Click

		Thisform.Scanner.SetFocus()
		KEYBOARD "0123456789{ENTER}" 

	ENDPROC

	PROCEDURE CtrlC.Click

		Thisform.Scanner.SetFocus()
		_CLIPTEXT = "0123456789" + CHR(13) + CHR(10)

	ENDPROC

ENDDEFINE

DEFINE CLASS ScannerBox AS TextBox

	WaitForCR = .NULL.
	Chronos = .NULL.
	
	PROCEDURE Init
		This.WaitForCR = CREATEOBJECT("WaitForCR")
	ENDPROC

	PROCEDURE GotFocus
		ON KEY LABEL Ctrl+V NOTE
	ENDPROC

	PROCEDURE LostFocus
		ON KEY LABEL Ctrl+V
	ENDPROC

	PROCEDURE Destroy
		This.WaitForCR.ScannerReference = .NULL.
	ENDPROC

	PROCEDURE Reset
		This.WaitingForCR(.F.)
		This.Chronos = .NULL.
		This.Value = ""
	ENDPROC

	PROCEDURE WaitingForCR (DoWait AS Logical)
		IF m.DoWait
			This.WaitForCR.ScannerReference = This
			This.WaitForCR.Interval = 20
			This.WaitForCR.Enabled = .T.
		ELSE
			This.WaitForCR.Enabled = .F.
			This.WaitForCR.Interval = 0
			This.WaitForCR.ScannerReference = .NULL.
		ENDIF
	ENDPROC

	PROCEDURE KeyPress (KeyCode AS Integer, ShiftAltCtrl AS Integer)

		LOCAL Now AS Double

		m.Now = SECONDS()

		DO CASE

		&& keyboard is being used
		CASE m.ShiftAltCtrl != 0

			This.Reset()
			NODEFAULT

		&& (re)start input
		CASE ISNULL(This.Chronos)

			This.WaitingForCR(.F.)
			This.Chronos = m.Now

			This.WaitingForCR(m.KeyCode != 13)

		&& quick enough
		CASE m.Now >= This.Chronos AND m.Now < This.Chronos + 0.020

			This.WaitingForCR(.F.)

			This.Chronos = m.Now
			This.WaitingForCR(m.KeyCode != 13)

		&& quick enough past midnight
		CASE m.Now < This.Chronos AND (m.Now + 86400) < This.Chronos + 0.020

			This.WaitingForCR(.F.)

			This.Chronos = m.Now
			This.WaitingForCR(m.KeyCode != 13)

		&& scanner not recognized
		OTHERWISE

			This.Reset()
			NODEFAULT

		ENDCASE

	ENDPROC

ENDDEFINE

DEFINE CLASS WaitForCR AS Timer

	ScannerReference = .NULL.

	PROCEDURE Timer
		IF !ISNULL(This.ScannerReference)
			This.ScannerReference.Reset()
			This.ScannerReference = .NULL.
		ENDIF
	ENDPROC

ENDDEFINE
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform