Main Site Documentation

KBE using USBC_Keyboard is there a way to get current keyboard state?


#1

hi,
is there a way to get the state of the keyboard
for example if I want to send a capital A. I need to know if to hold shift and then press a or not to.
in case capslock is on the shift will do the opposite than I want.
any way to get the state of the key?
thanks!


#2

Yes, check the documentation it has an example:

http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation%20v4.2/Premium/html/8facfb26-c803-26f2-80b1-0a3ee0409e00.htm

                    ...
                    // We need shift down for capital "H"
                    kb.KeyDown(USBC_Key.LeftShift);
                    kb.KeyTap(USBC_Key.H);
                    kb.KeyUp(USBC_Key.LeftShift);

                    // Now "ello world"
                    kb.KeyTap(USBC_Key.E); 
                    kb.KeyTap(USBC_Key.L); 
                    kb.KeyTap(USBC_Key.L); 
                    kb.KeyTap(USBC_Key.O); 
                    kb.KeyTap(USBC_Key.Space);
                    kb.KeyTap(USBC_Key.W); 
                    kb.KeyTap(USBC_Key.O); 
                    kb.KeyTap(USBC_Key.R);
                    kb.KeyTap(USBC_Key.L);
                    kb.KeyTap(USBC_Key.D); 
                    ...



#3

thanks but what I meant is how to know if specific keys are down
the example won’t work in case capsLock is on
then the example will type

!hELLO wORLD

and that is not what I want. I want it no matter what is the keyboard state to have printed
!Hello World


#4

@ Devloper123 - USBC_Keyboard class is used when you want your device to emulate a keyboard when connect to a PC. USBH_keyboard is the class to use when you want to connect a keyboard to your device.


#5

Are you sending or receiving keyboard events?


#6

sending key strokes.
but want the result to be the same no matter what is the current state of the keys,


#7

@ Devloper123 - I an confused. If you are sending from the MF device there are no physical keys. Please describe you configuration in detail.


#8

I assume he’s referring to instances where there is already a keyboard attached to the system his board is connected to. He wants to ensure that if the other keyboard has caps lock on, it won’t affect his device – and if it will, he’d like to detect that.

I’ve never done USB HID with multiple keyboards, so I’m not sure – do operating systems maintain a global caps lock status that applies to every keyboard? Or does caps lock only apply to the keyboard that activated it?

I assume the latter would be the case.


#9

@ jay - I would assume that the caps lock is local to a keyboard instance.best we not make assumptions, and get a better understanding what the OP is trying to do. :slight_smile: