Support Forums > Other Software and Code

Works with PowerBASIC but not with FireFly

(1/2) > >>

Jean-pierre Leroy:
Dear FireFly user,

For a specific form I would like to disabled CAPS LOCK (if set); for that purpose I use the function SetNumLock() below:

And in the WM_CREATE handler of the FORM I called it with these parameters:

--- Code: ---SetNumLock(%VK_CAPITAL, %FALSE)

--- End code ---


--- Code: ---Sub SetNumLock(VKkey As Long, bState As Byte)
   'Turn on and off caps lock, scroll lock and num lock
   'VKkey = %VK_CAPITAL, %VK_SCROLL, %VK_NUMLOCK
   'bState = %TRUE for on, %FALSE for off
   Dim keyState(256) As Byte
   Local pKeyState As Byte Ptr
   pKeyState = VarPtr(keyState(0))
   GetKeyboardState ByVal pKeyState
   If ((bState And Not (keyState(VKkey) And 1)) Or (Not bState And (keyState(VKkey) And 1))) Then
      Keybd_event VKkey, 0, %KEYEVENTF_EXTENDEDKEY, 0
      Keybd_event VKkey, 0, %KEYEVENTF_EXTENDEDKEY + %KEYEVENTF_KEYUP, 0
      keyState(VKkey) = bState
      SetKeyboardState ByVal pKeyState
   End If
End Sub

--- End code ---

If CAPS LOCKS is on before starting the program, within FireFly, CAPS LOCK led is switched off but the characters are still capitalized.
Within a PowerBASIC source code it works perfectly.

There is probably something related to FireFly, but I've no idea where to look at.

Thanks for your help.
Jean-Pierre

David Kenny:
Hello Jean-pierre,

Don't use that code... It's been mangled in some way.  Did some weird stuff on my machine (multi-line, pasted code ended up on the same line as if the CRLFs were stripped out). Had to reboot to fix it. Try this instead:

--- Code: ---If GetKeyState(%VK_CAPITAL) Then ToggleKey(%VK_CAPITAL) 'If it is on, toggle it off.

Sub ToggleKey(Key As Byte)
    Keybd_event 0, 0, 0, 0
    Keybd_event Key, MapVirtualKey(Key, 0), %KEYEVENTF_EXTENDEDKEY, 0
    Keybd_event Key, MapVirtualKey(Key, 0), %KEYEVENTF_EXTENDEDKEY Or %KEYEVENTF_KEYUP, 0
    Keybd_event 0, 0, %KEYEVENTF_KEYUP, 0
End Sub
--- End code ---

It works in PB and FF, I tested both.

Put the calling IF line anywhere.  Since the user can turn the capslock back on, you could check it regularly and keep turning it off.  You didn't tell us how you were going to use it.  Put it in Create if you only want it off at the start of the program. 

You can use it to manage the other toggle keys by changing the argument.

David

Jean-pierre Leroy:
Hi David,

Thanks a lot for your code. It works perfectly.


--- Quote ---You didn't tell us how you were going to use it.
--- End quote ---
I will try describe what I want to achieve.

For an inventory application, we use Zebra digital scanner DS3678.
We use it in what is called "Batch Only Mode" i.e. without any Bluetooth or Wifi connection.
The inventory is done by scanning the barcodes on products; after that the employee launch the inventory application (with a notepad like form to receive the datas); then he inserts the scanner in the cradle; Data transmission is triggered by insertion of the scanner into the cradle; the cradle itself is connected trough a USB HID Keyboard interface.

If CAPS LOCK is set, the barcodes are translated into upper case characters and we don't receive the right codes; it is why I was looking for a solution to disable CAPS LOCK

PS: now i have still to check that the cradle is well connected to the PC through the USB HID Keyboard interface; otherwise the whole data inventory will not be transmitted to the PC and will be probably lost !

Again thanks a lot for your help.
Jean-Pierre

David Kenny:
That's quite a coincidence Jean-Pierre.  I am currently working on a device I designed and built (a couple prototypes so far) that also identifies to Windows that it is an HID USB keyboard.  It's looks just like a flash drive, uses Bluetooth, and I control it with an app I wrote for Android phones.

Glad to hear it worked for you.

As for your PS:  It seems that your device should have been designed with that in mind.  It should have a button to send. That would send all the data it has each time it is pushed.  And a second one that must be held in for a bit to identify your wish to purge the data.  There are of course many ways to handle this, I'm only saying that there should be some way to avoid or mitigate loosing the data.

David

Jean-pierre Leroy:
David,

When the cradle is connected to the PC through the USB HID Keyboard interface, it appears in Windows 10 settings "Symbol Bar Code Scanner"; see the enclosed screenshot.

I'm looking the simplest function that would return %TRUE is the "Symbol Bar Code Scanner" is connected to the PC trough the USB HID Keyboard interface.

I've seen some code from Pierre Bellisle that would probably help me.

https://forum.powerbasic.com/forum/user-to-user-discussions/programming/767631-identify-usb-drive-letter?p=767726#post767726

Please tell me if you have other idea how to do that ?

Thanks,
Jean-Pierre

Navigation

[0] Message Index

[#] Next page

Go to full version