Pages: [1] 2   Go Down
Author Topic: Feasibility: Virtual Keyboard and ultra-fast keystrokes  (Read 1349 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First of all, i'm new here, so hi there smiley

Okay, this is what i'm trying to do;

I'm trying to build a keypad/keyboard, wich would be connected to a computer (like a regular keyboard),  that would be able to generate a big chunk of code by pressing only one button. Sort of like code hinting, but completely in hardware (i don't like code hinting and replacing apps). It should at least be able to generate if-loop templates, that kind of stuff.

So i looked around for a bit and found this:

http://books.google.be/books?id=iwzo1-zmVXEC&pg=PA58&lpg=PA58&dq=UsbKeyboard.sendKeyStroke+arduino&source=bl&ots=mNdlwVe071&sig=qkrH7LOVkSfcu2AEizhvMQpybGw&hl=nl&ei=HqjSTei9C4Sg-wbJudWtCg&sa=X&oi=book_result&ct=result&resnum=4&ved=0CD4Q6AEwAw#v=onepage&q=UsbKeyboard.sendKeyStroke%20arduino&f=false

So i thought that would pretty much fit my needs, BUT i'm still left with one question. In the example there's a loop wich types "hello world", but would this project be fast enough to type a simple block of template-code without too much lagg? And if it is, what's the limit of characters it could send without any lagg?

PS: If this is not a good idea, any other ideas on how to tackle this?


Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can do this a few different ways and the speed doesnt have to be a problem.  The biggest issue you'd run into is if you were attempting to use the on-board USB  jack on the arduino.   All comms through it are done via serial so speed would stink. 

You would get the best, and fastest results by buying a TEENSY or TEENSY++:
http://pjrc.com/teensy/teensyduino.html

The teensy can be programmed using the software above and is small, fast as heck, CHEAP, and easy to write for if you know Arduino. 

Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 504
Posts: 31324
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
All comms through it are done via serial so speed would stink. 
Come off it we are talking about a keyboard input to a text editor. It will go so fast that you won't see it coming in it will just appear.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Come off it we are talking about a keyboard input to a text editor. It will go so fast that you won't see it coming in it will just appear.

115200 is NOT as fast as 12 MBit/sec.  That said, I'll buy that it could be done QUITE DAMN FAST, but the overhead of mimicing an HID device can be messy and speed does suffer. He DID specify "ultra-fast" which as you know is 1,800 kindaFasts. I'm not sure the Arduino serial bus can support that kind of speed, captain!

Skipping the speed aspect, I'd also say that for ~$16 for the bigger one, the teensy is cheaper than building the hardware necessary to do a worse job with a standard Arduino. 

Also: I think they're neat. Can you tell I'm biased?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@brucethehoon, I must say that Teensy looks like a really good alternative for this compared to the arduino. Also it's a LOT smaller

I think i'll give the Teensy a shot smiley
Logged

0
Offline Offline
Full Member
***
Karma: 2
Posts: 156
It was all digital
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi viezefreddy

Is 100,000 chars in 15.2 sec too slow?

2000 lines with 50 chars in each line:
Code:
// Random code

const char letters[27] = {' ','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
unsigned long t1;

void setup(){
  Serial.begin(115200);
  randomSeed(3);                // random by dice-roll
  t1 = millis();
  for (int j=0; j<2000; j++){
    for (int i=0; i<50;i++){
      Serial.print(letters[random(0,27)]);
    }
  Serial.println();
  }
  Serial.println(millis()-t1); 
}

void loop(){
}


-Fletcher
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi viezefreddy

Is 100,000 chars in 15.2 sec too slow?

Not really no. And the code you posted works fine, but that's sending the characters to your serial monitor. You wouldn't be able to get them in a text editor this way because the arduino needs to function as an input device
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 504
Posts: 31324
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You wouldn't be able to get them in a text editor this way because the arduino needs to function as an input device
All you need is a small program on the PC side to receive serial and squirt it into the keyboard input stream.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You wouldn't be able to get them in a text editor this way because the arduino needs to function as an input device
All you need is a small program on the PC side to receive serial and squirt it into the keyboard input stream.

Well i know this would work, but that wouldn't exactly make it plug-and-play. You'd still need an application running in order for it to work.

The Teensy board mentioned earlier doesn't need this
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 504
Posts: 31324
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Well i know this would work, but that wouldn't exactly make it plug-and-play.

So all of a sudden you want a plug and play solution, it would have been so good to mention that at the outset.
Logged

0
Offline Offline
Full Member
***
Karma: 2
Posts: 156
It was all digital
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Quote
He DID specify "ultra-fast" which as you know is 1,800 kindaFasts. I'm not sure the Arduino serial bus can support that kind of speed, captain!

.... hummm ...

Quote
USB Keyboard speed is limited to 500 keystrokes per second, and some operating systems may limit the speed to only 62.5 keystrokes per second. There is nothing you can do about these limits. Reading the rest of this section will only help you understand why they exist.

The HID protocol is used by USB keyboards, and HID uses the USB "interrupt" transfer type, which allocates 1 packet per a configurable number of USB frames. Each USB frame is 1ms, and the Teensyduino USB keyboard code requests the interval to be every frame. If the operating system honors this request, bandwidth is available for 1000 packets per second.

Arduino serial protocol was able to push 6579 keystrokes per second.

I'm not sure the HID protocol can support that kind of speed, captain!

-Fletcher
Logged

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can also go faster than 115200 pretty safely with arduino's serial it's just that the serial monitor doesn't support any higher.

With the uno you can program HID onto the 8U2 easily too (but as said - plug and play wasn't stated).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So all of a sudden you want a plug and play solution, it would have been so good to mention that at the outset.

Mhm, i did mention something about doing this completely in hardware but i guess i could have stated that a lot clearer.

Sorry about that.

So if i understand correctly, an HID Teensy would clock in at 1 keystroke per millisec or 1000 per second. And an arduino + processing app could reach 6579 (like Fletcher said).

Is there any way other than software running on the pc to overcome this speed issue?
Logged

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there any way other than software running on the pc to overcome this speed issue?
Quote
With the uno you can program HID onto the 8U2 easily too

I wouldn't say 1k chars per second is exactly slow - the software running on the host PC probably can't receive them that fast (or can't display them that fast).
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there any way other than software running on the pc to overcome this speed issue?
Not that I've ever seen. 

I think it's worth noting that the speeds given above are not apples to apples comparisons.  One gives the speed as defined in an application (HID keyboard input) and another gives the speed in raw input from serial.  Mileage will vary when trying to DO something with the input from that serial connection.

I've done something essentially identical to what you're doing using an attiny85 for a World of Warcraft macro keypad.  I made it for someone, so i don't have it in front of me, but it used a 6x6 external i2c keypad.  I DID use serial with a windows C# based service looking for input from serial that would then lookup the desired macro from a local SQL server lite db then echo it to the system via the API.   

This wasn't LIGHTNING fast, but it was good.   If you want a COMPLETELY standalone system, i.e. A box with a USB port and some buttons, you will end up wanting to make it easy to Ganges out your snippits easily.  A panel mounted SD card slot connected to whichever MP you go with is probably the most obvious option.   The last time I did something like that, I made a dir structure on the SD card, one directory for each modifier key - essentially I had 4 modifier keys that could be pressed FIRST and in combination with my main keys.  Into those dirs, I put a folder for each main key.   

If I were doing this myself, I'd use the teensy because its small and the HID support makes it ultimately portable on any machine.   I'd then throw an LCD on it - a nice high res OLED perhaps - and have it display, at rest, a basic list of keys with a hint, then when pressed, display the text about to be inserted. 

I'm going to back off on the speed issue here, though...  When Mike steps in, I'm outclassed.

Also: mowcius
Logged

Pages: [1] 2   Go Up
Jump to: