Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to programmatically set the state of the shift and control keys?

Tags:

keyboard

The reason I am asking is that I am thinking of building a foot switch to act as shift and control keys - well two switches, one for each foot.

I'm planning on using the Arduino for this and writing a small C# application to detect when the switch has been pressed that would then set the state of shift or control. I would rather not have to write a keyboard driver for the Arduino as I would like it to do other things as well.

like image 763
Stephen Harrison Avatar asked Mar 27 '10 00:03

Stephen Harrison


People also ask

What happens when Shift key is pressed 5 times?

Without pressing other keys, press the SHIFT key five times to enable Sticky Keys. A window will be displayed asking you if you wish to turn on Sticky Keys (Figure 2). Clicking Yes will enable Sticky Keys.

Which key is used for Shift?

The Shift key is located in the second row of keys from the bottom on the far left, above the Ctrl key. There is a ⇧ symbol on the key. What is the function of the Shift key? The Shift key is a so-called control key on the computer keyboard.

What is the function of Shift click?

Practice Shift-clicking Hold down either Shift on the keyboard. While continuing to hold down the Shift , click at the end of the text or where you want to stop highlighting. If done correctly, all text in-between the two areas clicked becomes highlighted.


1 Answers

Yes it is possible, but you will have to pInvoke out to Win32. Have a look at the keydb_event call.

[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

You can then call:

keybd_event(0x10, 0, 0, 0);

to turn on the shift key (ie. key down), and:

keybd_event(0x10, 0, 2, 0);

to turn it off again (ie. key up).

The first argument is the hex value of the key to press:

  • 0x10 = shift
  • 0x11 = ctrl
  • 0x12 = alt

I've just tried this in a simple C# application using a checkbox to represent the shift key. With it checked, it "held" the shift key in for any application I used.

like image 151
adrianbanks Avatar answered Oct 12 '22 15:10

adrianbanks