Ask a Question

How to Send "Right Alt" key using shell object.

manojgovikari
Contributor

How to Send "Right Alt" key using shell object.

Hi,

As per our requirement we need to press Right Alt key while script is running.

We are using code as below.

Set objshell = CreateObject("WScript.Shell")

objshell.sendkeys "RALT"



the above code is not working. we also tried with "RAlt", "[RALT]", "Right Alt", "RAltGr"... but none of them worked.



Please let me know the correct key for select the right alt key button on keyboard.



Thanks,
Thanks,
Manoj Govikari
12 REPLIES 12
HKosova
Moderator

RE: How to Send "Right Alt" key using shell object.

Hi,



According to the WshShell.SendKeys method description, it seems that it doesn't support pressing the right Alt specifically.

Use TestComplete's Keys or Sys.Desktop.KeyDown method instead:

"



' -- or --



Sys.Desktop.KeyDown Win32API.VK_RMENU

' Do something

Sys.Desktop.KeyUp Win32API.VK_RMENU

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
manojgovikari
Contributor

RE: How to Send "Right Alt" key using shell object.

Thanks for the response.

I tried using the win32API codes also. But it is not worked. Actually need to apply the Right Alt + Right Shift key to change the input method in the application.



key down/ key up methods also not working. While script running need to pass these keys to change input methods.



Kindly help me in selecting the Right Alt + Right shify key combination to enable input method in the application and also please provide the code for Right Shift + Space key combination.


Thanks,
Manoj Govikari
manojgovikari
Contributor

RE: How to Send "Right Alt" key using shell object.

I could able to press Right Alt key with the below code.

Sys.Desktop.KeyDown(21).



Please help me to give the combination of Right Alt and Right Shift key using the KeyDown method.
Thanks,
Manoj Govikari
HKosova
Moderator

RE: How to Send "Right Alt" key using shell object.

Hi,



Try the aqEnvironment.SetKeyboardLayout method instead:





However, depending on your test case, this operation might not be needed at all. For example, TestComplete's Keys method supports multi-language text input:



Set edit = Sys.Process("notepad").Window("Notepad").Window("Edit")

edit.Keys "Hello, world!" & [Enter] & "¡Hola, mundo!" & [Enter] & "Γεια σου κόσμε!" ' English, Spanish & Greek

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
manojgovikari
Contributor

RE: How to Send "Right Alt" key using shell object.

As per the test case, i need to press Right Alt + Right shift key to enable Korean input method.



Please provide the key for pressing this combination. and also provide the key code for sending Shift + Space
Thanks,
Manoj Govikari
manojgovikari
Contributor

RE: How to Send "Right Alt" key using shell object.

for selecting "Right Alt"  we used code as - Sys.Desktop.KeyDown(21). Similary provide us the code for selecting the combination of Right Alt and Right Shift  and Shift + Space
Thanks,
Manoj Govikari
manojgovikari
Contributor

RE: How to Send "Right Alt" key using shell object.

Virtual Key codes are changing with the different system configurations.

ex:

dell optiplex 740 - virtual key code for "Right Alt" key is - 21

dell optiplex 620 - virtual key code for "Right Alt" key is - 165.



Please help us to avoid such conflicts.
Thanks,
Manoj Govikari
HKosova
Moderator

RE: How to Send "Right Alt" key using shell object.

Hi,



Virtual Key codes are changing with the different system configurations.


You can use named constants from the Win32API object instead of hard-coded values:



Note: You may need to use VK_HANGUL or VK_KANA instead of VK_RMENU; Unfortunately I don't have the Korean input language to test them, so please check this yourself.





Similary provide us the code for selecting the combination of Right Alt and Right Shift and Shift + Space


For Shift+Space, use:





For Right Alt + Right Shift, try one of the following:

")

Call Sys.Keys("[Hold][X" & Win32API.VK_RMENU & "][X" & Win32API.VK_RSHIFT & "][Release]")


Alternatively, you can activate the Korean input language programmatically using the aqEnvironment.SetKeyboardLayout method:



The benefit of using the SetKeyboardLayout method is that it works regardless of the keyboard shortcut used to switch between the input languages (Alt+Shift, Ctrl+Shift and so on).



Please let me know how all this works for you.

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
manojgovikari
Contributor

RE: How to Send "Right Alt" key using shell object.

Thank you so much for all your clarifications.

All the key combinations are worked properly except the "Right Alt" key. This key is selecting only if i use below code

Sys.Desktop.KeyDown(21)

Sys.Desktop.KeyUp(21)



In my system it showing as Unknown key and virtual key code is - 21. Is this issye with keyboard or anything in the system configuration.

with Sys.Desktop.KeyDown(Win32API.RMENU) is not working. Please let me know the solution for this issue.
Thanks,
Manoj Govikari
cancel
Showing results for 
Search instead for 
Did you mean: