简体   繁体   中英

Easiest way to get a wired signal into a PC?

for a prototype we need to have a hardware switch (eg, a momentary pushbutton) trigger the taking of a screenshot on a PC and save it to file. Writing some windows software to take a screenshot and save it is trivial, the slightly trickier part is how to get an electrical signal (we can choose the voltage, and provide power as necessary) to the software. We absolutely want to keep this simple (ie, no labview or anything) and reliable as possible. I see small module boxes such as this

https://labjack.com/products/u3?gclid=EAIaIQobChMI-MXkjcbB2gIVxVYNCh3C6AODEAQYAiABEgK_OvD_BwE

available, but are there even simpler solutions? I'm thinking of (but haven't taken the time to test) possibly a parallel-port-to-USB converter (which would be similar to the more common RS232-to-USB converter but may allow detection of individual high/lows(just a guess, never worked with a parallel driver from windows)), or something like that. Just querying for ideas before I spend time buying things and testing. Thanks!

This can be easily done with an Arduino Leonardo, Micro, and Due module. This page has an example very similar to your project:

// use this option for OSX:
char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux:
//  char ctrlKey = KEY_LEFT_CTRL;  

void setup() {
  // make pin 2 an input and turn on the 
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);
  // initialize control over the keyboard:
  Keyboard.begin();
}

void loop() {
  while (digitalRead(2) == HIGH) {
    // do nothing until pin 2 goes low
    delay(500);
  }
  delay(1000);
  // new document:
  Keyboard.press(ctrlKey);
  Keyboard.press('n');
  delay(100);
  Keyboard.releaseAll();
  // wait for new window to open:
  delay(1000);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM