How to press <Alt>+<Shift> simultaneously?

Status
Not open for further replies.

v_iv

New member
I have problem with buttons when coding teensy 2.0++.
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!
For switching keyboard's layout I am trying to simulate pressing
of <Alt>+<Shift> by different ways but unsuccessfully!
The most simple construction

Keyboard.set_modifier(MODIFIERKEY_LEFT_ALT);
Keyboard.set_key1(MODIFIERKEY_LEFT_SHIFT);
Keyboard.send_now();
delay(1500);
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();

does not work and I can not understand why. Who knows please help.

Thanks.
 
I'm not familiar w/ the libraries in use, but the comments appear to point to those constants corresponding to bits (e.g. use bitwise operators)

// modifier |= MODIFIERKEY_LEFT_SHIFT;
// modifier |= MODIFIERKEY_LEFT_ALT;
so:

Keyboard.set_modifier(MODIFIERKEY_LEFT_SHIFT | MODIFIERKEY_LEFT_ALT);
or
modifier = MODIFIERKEY_LEFT_SHIFT;
modifier |= MODIFIERKEY_LEFT_ALT;
Keyboard.set_modifier(modifier);

Like I said - just a guess, but I didn't see any replies yet and I'll bet that's what you're looking for.

http://en.wikipedia.org/wiki/Bitwise_operations_in_C
 
Last edited:
I tried constructions:

modifier = MODIFIERKEY_LEFT_SHIFT;
modifier |= MODIFIERKEY_LEFT_ALT;
Keyboard.set_modifier(modifier);
Keyboard.send_now();
delay(2500);
Keyboard.set_modifier(0);
Keyboard.send_now();

and

Keyboard.set_modifier(MODIFIERKEY_LEFT_ALT | MODIFIERKEY_LEFT_SHIFT);
Keyboard.send_now();
delay(2500);
Keyboard.set_modifier(0)
Keyboard.send_now();

They do not work both. (In different computers with Windows 7).
Thank you for the link, but I know bitwise_operations (not only in C).
I think there is another problem here. Is there a method
"ActivateKeyboardLayout(hkl,flags)" in class "Keyboard" ? I couldn't find.
May be it is called here by another name?
 
Ah, bummer :( Sorry to hear that it wasn't such a simple fix after all. As I said, it was a stab in the dark on my part. Sorry for assuming you didn't know about ORing bits together; it wasn't clear of those commented lines were yours or from an example.

In any case, good luck finding a solution!
 
Status
Not open for further replies.
Back
Top