PDA

View Full Version : Having the hardest time with code that simply duplicates a mouse click or f5 push...



thefed17
09-23-2013, 03:19 PM
I'm trying to make a button for Breeze systems that acts as an F5 OR left mouse click. Ive tried both after agonizing over this for days. I have made many buttons for another program that simulate a space bar push. This though is killing me. Below are 2 things I've done...both result in a bunch of this ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" when I click the button:
I have my button wires to the grnd and c7 pins like i always do for the other buttone:



VERSION 1


/*
* Button.pde
*/

void setup() {
Serial.begin(9600);
pinMode(10, INPUT_PULLUP);
delay(4000);
}

void loop() {
if (digitalRead(10) == HIGH) {

}
else {
Mouse.set_buttons(1, 0, 0); // hold left button
Mouse.set_buttons(0, 0, 0); // release button after move
delay(500);
}

AND

/*
* Button.pde
*/

void setup() {
Serial.begin(9600);
pinMode(10, INPUT_PULLUP);
delay(4000);
}

void loop() {
if (digitalRead(10) == HIGH) {
delay(10);
}
else {
Keyboard.set_modifier(0);
Keyboard.set_key1(KEY_F5);
Keyboard.send_now();
releasekey();
delay(500);
}

void releasekey() {
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}

v_iv
10-14-2013, 06:09 AM
It seems to me you have missed one important line:
"Keyboard.begin();" at the beginning.

I have similar problem with buttons. Could you hint
me how to press two buttons <Alt>+<Shift> simultaneously?

Exactly saying my problem is: this code
uint8_t key, modifier=0;
void setup()
{
delay(15000);
Keyboard.begin();
// switch_on_lat();
run("cmd");
delay(2000);
// switch_on_lat();
Keyboard.print("echo Hello!");
delay(1000);
Press_Enter();

delay(5000);
Keyboard.print("exit");
delay(1000);
Press_Enter();
}

void loop()
{
}

void switch_on_lat()
{
// modifier |= MODIFIERKEY_LEFT_SHIFT;
// modifier |= MODIFIERKEY_LEFT_ALT;
// Keyboard.set_modifier(MODIFIERKEY_LEFT_ALT);
Keyboard.set_key2(MODIFIERKEY_LEFT_ALT);
// Keyboard.send_now();
// Keyboard.press(KEY_LEFT_ALT);
// delay(1500);
Keyboard.set_key1(MODIFIERKEY_LEFT_SHIFT);
Keyboard.send_now();
// Keyboard.press(modifier);
delay(2500);
// Keyboard.set_modifier(0);
// Keyboard.send_now();
// Keyboard.releaseAll();
Keyboard.set_key2(0);
Keyboard.set_key1(0);
Keyboard.send_now();
// delay(1000);
}

void run(char *SomeCommand){
Keyboard.set_modifier(MODIFIERKEY_RIGHT_GUI);
// simulate pressing of button <Windows>
Keyboard.set_key1(KEY_R);
// simulate pressing of button <R>
Keyboard.send_now();
// Send combination <Windows>+<R>, which opens window "exec"
delay(1500);
Keyboard.set_modifier(0);
// simulate releasing of button <Windows>
Keyboard.set_key1(0);
// simulate releasing of button <R>
Keyboard.send_now();
// release combination <Windows>+<R>

Keyboard.print(SomeCommand);
// enter an argument into window "exec"
Keyboard.set_key1(KEY_ENTER);
Keyboard.send_now(); // press <Enter>
Keyboard.set_key1(0);
Keyboard.send_now(); // release <Enter>
// Press_Enter();
}

void Press_Enter()
{
Keyboard.set_key1(KEY_ENTER);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
}

works good under Windows-7 if the default input langauge
is English. Else it doesn't work!
I am trying to simulate pressing of <Alt>+<Shift> but
unsuccessfully! Please help.

Thanks.