Hi all expert guys here. as the title said about. I need some hint about how to do. Thank you very much.
godofwar2020:
as the title said about.
Might just be me, but no idea what the title means...
Not clear to me if the buttons are on the Arduino or the PC, and if the program that needs opening and closing is on the Arduino or the PC.
Step us through where the buttons and the program are, and what's supposed to happen when you press either or both buttons.
edit: is this to do with the use of the Leonardo as a keyboard?
sorry my bad english.
2 buttons are on arduino leonardo, one for open, the other for close program on PC.
godofwar2020:
2 buttons are on arduino leonardo, one for open, the other for close program on PC.
12Stepper:
is this to do with the use of the Leonardo as a keyboard?
The Leonardo keyboard.h library allows it to act as (takeover from) the PC's actual keyboard. So a button press on the Leo could generate a message that arrives at the PC as if it had been typed on the PC keyboard.
You would need to have something on the PC to take that keyboard command in, and act on it of course.
This example sends a message (hardcoded into the sketch) on a button press, and (provided you know how to handle it at the PC end) presumably that could trigger the opening or closing of a PC program.
Thanks for the hint. Can i make a shortcut key link to open a program and a another to close ? for example
CTRL+ALT+O for open and CTRL+ALT+C to close. and how about to handle if 2 button pressed at same time ?
godofwar2020:
Thanks for the hint.
I actually just edited that example to ping my router with...
Keyboard.print("ping 192.168.0.1\n");
... which works, but I have to have a dos box open with the cursor there.
godofwar2020:
Can i make a shortcut key link to open a program and a another to close ? for example
CTRL+ALT+O for open and CTRL+ALT+C to close
No idea... sorry ![]()
godofwar2020:
and how about to handle if 2 button pressed at same time ?
It's impossible for 2 buttons to become pressed at the same time; one will always be first. So if you need to handle 2 buttons being pressed at once, you would need to monitor the state of either button for pressed, and do nothing until a certain time has elapsed; then if only the first button is still pressed send one message, and if the other became pressed meantime, send a different one.
(That's not a Leo keyboard thing, that's an Arduino thing.)
The answer to your question might depend on the operating system that your using.
Under Windows, sending (that is, control plus escape) will open the start menu. Next you can send the name of the program followed by to start the program.
Closing an GUI application is usually done with (both Windows and Linux); the application must be the top window for that to work (there are more than likely ways around that with batch files and the likes).
sterretje:
Under Windows, sending (that is, control plus escape) will open the start menu. Next you can send the name of the program followed by to start the program.
fom the keyboard does indeed open the start menu, but it's not a place where you can type. So even from the keyboard, you can't enter the name of the program to run, at least I can't anyway. I think you need to open search, to type there, but I don't see a keyboard shortcut for that.
But let's say there is a shortcut to open a place where the command can be typed in, how do you put things like and in a .print()?
edit... We could escape as \x1b, but ?
Win-R opens the "Run" dialog (command line).
12Stepper:
It's impossible for 2 buttons to become pressed at the same time; one will always be first.
Wouldn't be too sure about that. Unless you are using interrupts - which you certainly should not! ![]()
You can; I use it all the time to find a program
(Windows 8 and 10 and, if not mistaken 7 as well).
Alternatively, type run in the start menu and next give the full path for the 'executable'. Advantage is that even programs that are not in the path can be started.
Paul__B:
Win-R opens the "Run" dialog (command line).
But can you code that in a Keyboard.print() so that the next line, the name of the program, will be as if it was typed there? (I ran ping from Keybaord.print() but had manually opened a dos box and given it focus.
You use Windoze 8?
![]()
sterretje:
You can; I use it all the time to find a program
Yeah you're right: must have had a brain fart finger trouble when I tried that a few minutes ago.
12Stepper:
But can you code that in a Keyboard.print() so that the next line, the name of the program, will be as if it was typed there? (I ran ping from Keybaord.print() but had manually opened a DOS box and given it focus.
I have no idea as I do not know what Keyboard.print() does. Obviously a HID keyboard can issue a "Win" modifier, so any emulation must be able to.
It's impossible for 2 buttons to become pressed at the same time;
Wouldn't be too sure about that.
You surely can't actually physically press two keys at the exact same instant? (At least not by more than fluke). So if you where whizzing through loop() and got to (pseudocode) while only b1 was pressed:
if (b1 is pressed and b2 is pressed)
... that test would fail.
And if there was a:
if(b1 is pressed)
... it would pass, before b2 got pressed.
That's what prompted me to say you need to check b1 for pressed, but before acting on it, you need to wait to see if b2 gets pressed.
But back to the main question: how do you code a "control-escape" into a Keyboard.print(), so that the next Keyboard.print(ping) will have a home?
Fluke make good equipment.
![]()
Paul__B:
Fluke make good equipment.
I popped the 10A fuse in mine (still not sure how, but whatever) and the branded replacement fuse costs more than most other bloody meters.
And the distributor of the fuses themselves (Siba?) wanted to sell me a box of 20. So right mow my Fluke is on mA duty only, which is ok for Arduining anyway.