Pages: [1] 2   Go Down
Author Topic: "Serial.print" special keys?  (Read 672 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've written a simple script where I press a button, which in turn Serial.prints a keystroke. My next step is to use that to activate a keyboard shortcut...a combination of two keys pressed simultaneously.

So I'm wondering two things:

1. Is it possible to Serial.print something that's not a character, like Ctrl, Shift, or Command?

2. If so, can you Serial.print two keys at the same time, perhaps with a delay(1000) after Serial.printing the first key?

Or would you guys suggest a better way to go about this?
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Serial/Write

send the ascii code
Logged


Land of Oz
Offline Offline
Jr. Member
**
Karma: 3
Posts: 72
I dream in Assembler
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

We did this in the "days of DOS". Take the interpreted key code character. There is a DOS service call that returns the scan code for non-printable keys...
if thats any help to get you started.
Logged

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What you're looking for is to turn your arduino into a USB keyboard. You can do it with an uno, but it's much easier with an arduino leonardo (google it in either case)
Logged

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

Hm, well then a follow-up: how would I get it to "press" a special key, like F6? On a friend's advice, I tried
Code:
Serial.print("key_f6");
, but looking at the serial monitor, I think it's just printing key_f6 as a string.
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What WizenedEE said (did you see his message?) 

With Uno you would need v-usb or equivalent.  Leonardo or Teensy --> very easy.
Logged

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

Quote
With Uno you would need v-usb or equivalent.

Looks like I'm s.o.l. with my UNO then. As far as I can tell, I'd need to download a DFU Programmer first. I can't do that without installing MacPorts, and I can't install MacPorts without Xcode, and I can't install Xcode 4 (the only one Mac makes available now) on Mac 10.6.

Grr.

Any other thoughts? All I want to do is have Arduino send a signal to launch a script that plays a particular song (in iTunes, Quicktime, whatever application I can). I was thinking I could do it with a button: press the button, which signals a keyboard shortcut, which launches a script to play the song. So it looks like that approach is out, at least with my UNO/O.S. combination.

Is there a whole different angle I could take?
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not so sure that you're SOL, but I'm getting out of my zone here-- I have used Teensy for things like that, it's dirt simple and it has usb dongle-like format...
Logged

Land of Oz
Offline Offline
Jr. Member
**
Karma: 3
Posts: 72
I dream in Assembler
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
With Uno you would need v-usb or equivalent.

Any other thoughts? All I want to do is have Arduino send a signal to launch a script that plays a particular song (in iTunes, Quicktime, whatever application I can). I was thinking I could do it with a button: press the button, which signals a keyboard shortcut, which launches a script to play the song. So it looks like that approach is out, at least with my UNO/O.S. combination.

Is there a whole different angle I could take?

Are you simply doing this as an intellectual exercise or just because you're bored ?  Seems like an awful lot of work just to play a music download. I would just buy an old laptop and get a illegal COUGH ! real copy of Windoze or whatever and use that.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4019
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

F6 is ASCII 246 decimal, 11110110 binary. Try writing that.

http://www.ascii-code.com/

Logged

Examples can be found in your IDE.

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

Quote
Are you simply doing this as an intellectual exercise or just because you're bored ?  Seems like an awful lot of work just to play a music download. I would just buy an old laptop and get a illegal COUGH ! real copy of Windoze or whatever and use that.

lol. Isn't everything an intellectual exercise?  smiley I'm doing a silly project to learn about pairing a sensor and a computer, beyond the basic serial monitoring. I have a waterproof thermometer, and when it senses a pot of water has reached 100 deg. Celsius (that the water is boiling) I want it to tell the UNO to tell the computer to play an .mp3 clip of a James Brown yell.
Logged

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

F6 is ASCII 246 decimal, 11110110 binary. Try writing that.

http://www.ascii-code.com/



That's still basically a character, as opposed to the function key F6. Someone might have mentioned it up-thread or I saw it somewhere else today, but I've learned you can't print function keys, Crtl, Shift, etc. in the programming sense. At least not without turning my Arduino into a USB keyboard, per WizenedEE's reply and stuff I've read elsewhere.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4019
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So you tried and it didn't work. Because we all know that all PC programs work the same...
Logged

Examples can be found in your IDE.

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

So you tried and it didn't work. Because we all know that all PC programs work the same...


Sorry?
Logged

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

F6 is ASCII 246 decimal, 11110110 binary. Try writing that.

http://www.ascii-code.com/

The serial monitor reads from the serial port and displays the character on a java TextBox. You can't generate a system-event, such as the one pressing F6 does, by displaying a character on a textbox.
Logged

Pages: [1] 2   Go Up
Jump to: