PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 23 → window information when barcode scann (GetAsyncKeyState api ?)
window information when barcode scann (GetAsyncKeyState api ?)
Débuté par trian, 04 sep. 2018 21:30 - 6 réponses
Posté le 04 septembre 2018 - 21:30
I try to make a program that popup window information when user scan barcode . The problem is that program maybe not have focus at this time . So i make a procedure running on timer and i try to grup the barcdode reader with out of luck.
i need to use something like GetAsyncKeyState system api , when the program is running on background and not have focus i try GetAsyncKeyState but i need to declare the key pressed parameter , how can declare that? or anyone have any other idea?
Posté le 04 septembre 2018 - 22:40
Hi

there are 2 ways for barcode readers to function: as keyboard emulation,
or as a barcode reader.

The second way allows to capture events/scans easily, but is dependent
on using the barcode maker API/SDK/Documentation... This is the way to
go to obtain the described result.

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Free Video Courses, free WXShowroom.com, open source WXReplication, open
source WXEDM.

More information on http://www.fabriceharari.com


On 9/4/2018 1:30 PM, trian wrote:
I try to make a program that popup window information when user scan
barcode . The problem is that program maybe not have focus at this time
. So i make a procedure running on timer and i try to grup the barcdode
reader with out of luck. i need to use something like GetAsyncKeyState
system api , when the program is running on background and not have
focus i try  GetAsyncKeyState  but i need to declare the key pressed
parameter , how can declare that? or anyone have any other idea?
Membre enregistré
23 messages
Posté le 05 septembre 2018 - 07:22
Hello,
Thank you for answer. Clients have different type of barcode readers so i thing i need to use the keybord emulator hard way.
Posté le 05 septembre 2018 - 14:33
Hi again,

On 9/4/2018 11:22 PM, Mister TRIANTAFILLOS wrote:
Hello,
Thank you for answer. Clients have different type of barcode readers so
i thing i need to use the keybord emulator hard way.


well, in keyboard emulation, you question becomes: how to intercept
keystrokes when my program doesn't have focus; and even worse than that,
how to recognize that the keystrokes in question are coming from the
barcode reader.

The only thing that comes to mind is to:
1. configure the barcode reader so that it adds a special char (your
choice) at the beginning of the barcode. All barcode readers should be
configurable that way.

2. add a key HOOK (see windows api) on that special char at the windows
level (AFAIK, you will need admin privileges to do that, so your program
will have to be run at least once in elevated privileges mode)... When
you do that, your program will be called and you will be able to get the
focus back and hence the barcode... Not tested, but that SHOULD work.

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Free Video Courses, free WXShowroom.com, open source WXReplication, open
source WXEDM.

More information on http://www.fabriceharari.com
Membre enregistré
23 messages
Posté le 05 septembre 2018 - 18:07
I was able to read the barcode scanner or the keyboard without having the focus on my program.
The code is below, procedure running timer scedule infinite.
Now I want to find a way to recognize if the user use input keyboard or a scaner, do not run the code procedure if not uses the keybord.


// Automatic Procedure:
// The procedure is run manually, during a call in the code
// It will be repeated in loop, with a timeout set to 1 hundredths of a second between each call
// Each following call runs the procedure once, without timer
//

Procedure check_GetAsyncKeyState()

GetAsyncKeyState is API Description
GetAsyncKeyState..DLLName = "user32" //user32.dll
GetAsyncKeyState..FunctionName = "GetAsyncKeyState"
GetAsyncKeyState..ReturnType = apiSystemInt
GetAsyncKeyState..Parameter[1]..Type = apiInt_4

// Direct use
//GetAsyncKeyState(Null)

nResult_tmp is int
sKey_tmp is string
i is int

IF GetAsyncKeyState(i) <>0 THEN
Info(GetAsyncKeyState(i))
END
FOR i = 2 TO 90
nResult_tmp = 0
nResult_tmp = GetAsyncKeyState(i)

// nResult_tmp = -32767 when keybord or barcode scanner hit and focus on location that can edit - whrite
// nResult_tmp = 1 when keybord or barcode scanner hit and focus on location that can't edit - whrite
IF nResult_tmp = -32767 OR nResult_tmp = 1 THEN
sKey_tmp = Caract(i)
IF i = 13 THEN //enter key hit
sKey_tmp = CR
END
EDT_NoName1= EDT_NoName1 + sKey_tmp
END
END
Membre enregistré
22 messages
Posté le 17 septembre 2018 - 17:35
Try this link.

https://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard

This can handle multiple keyboard output.
You can identify the input device you used.
Membre enregistré
23 messages
Posté le 17 septembre 2018 - 19:58
Thank you for your answer.
My code with GetAsyncKeyState its not working all the time and its not working for what i need if user do fast scans.
Yes its better solution raw input system api handler.
I make a new code... with raw inpup code i have 100% the barcode input.