Go Down

Topic: "Serial.print" special keys? (Read 888 times) previous topic - next topic

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?

Osgeld

http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

greywolf271

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.

WizenedEE

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)

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: [Select]
Serial.print("key_f6");, but looking at the serial monitor, I think it's just printing key_f6 as a string.

johncc

What WizenedEE said (did you see his message?) 

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

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?

johncc

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...

greywolf271


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.

GoForSmoke

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

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

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

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?  :) 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.


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.

GoForSmoke

So you tried and it didn't work. Because we all know that all PC programs work the same...
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts


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



Sorry?

WizenedEE


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.

Go Up