Winium.Desktop icon indicating copy to clipboard operation
Winium.Desktop copied to clipboard

Doesn't work key simulation ( send_keys )

Open LarryDi opened this issue 7 years ago • 8 comments

Winium.Desktop v.1.6.0 Selenium v.3.0.2 Python v.3.4.4

Using examples from Wiki and habrahabr article:

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Remote(
    command_executor='http://localhost:9999',
    desired_capabilities={
        "debugConnectToRunningApp": 'false',
        "app": r"C:/windows/system32/notepad.exe"
    })

time.sleep(0.5)
window = driver.find_element_by_class_name('Notepad')
text_field = window.find_element_by_class_name('Edit')

text_field.click()
text_field.send_keys('Some text{ENTER}{ENTER}')

actions = ActionChains(driver)
actions.send_keys('Another text{ENTER}')
actions.send_keys('^{o}')
actions.perform()

ActionChains(driver).key_down(Keys.CONTROL).send_keys('o').key_up(Keys.CONTROL).perform()
ActionChains(driver).key_down('\ue009').send_keys('o').key_up('\ue009').perform()

Result: "Some text{ENTER}{ENTER}Another text{ENTER}^{o}oo" Keys simulation does not work.

Is it bug or i do something wrong? If the second, what exactly wrong?

LarryDi avatar Mar 30 '17 14:03 LarryDi

for me also not working, i'm using windows.forms.sendkeys class in c# for key combos.

heilwood avatar Apr 13 '17 11:04 heilwood

if you would like to send Enter using actions or any other button you need to add to dictionary Modifiers and ModifiersMap keys which you want to use in class KeyboardModifiers. Then you can use actions = ActionChains(driver) actions.send_keys(Keys.Enter).send_keys('some_Text').send_keys(Keys.Enter)

heilwood avatar Jul 06 '17 07:07 heilwood

add to dictionary Modifiers and ModifiersMap keys which you want to use in class KeyboardModifiers ? What library I want to import to simulate keyboard keys i.e. ENTER, BACKSPACE.?

Ahsanmumtaz1105 avatar Aug 21 '17 14:08 Ahsanmumtaz1105

If you would like to have this in winium you should download source code of the project, add required keys to dictionary ModifiersMap which is in class Modifiers.cs, then compile the project.

heilwood avatar Aug 28 '17 06:08 heilwood

It doesn't work for me too,I tried actions and sendkeys. I ended up using awt robot and it works.

SanjeevKumarmn avatar Nov 04 '17 04:11 SanjeevKumarmn

Winium.Desktop.Driver\Winium.Desktop-1.6.0\src\Winium.Desktop.Driver\Input\KeyboardModifiers.cs

internal class KeyboardModifiers : List { #region Static Fields

    private static readonly List<string> Modifiers = new List<string>
                                                         {
                                                             Keys.Control, 
                                                             Keys.LeftControl, 
                                                             Keys.Shift, 
                                                             Keys.LeftShift, 
                                                             Keys.Alt, 
                                                             Keys.ArrowDown,
                                                             Keys.ArrowUp,
                                                             Keys.PageDown,
                                                             Keys.PageUp,
                                                             Keys.LeftAlt
                                                         };

    private static readonly Dictionary<string, VirtualKeyCode> ModifiersMap =
        new Dictionary<string, VirtualKeyCode>
            {
                { Keys.Control, VirtualKeyCode.CONTROL },
                { Keys.Shift, VirtualKeyCode.SHIFT },
                { Keys.Alt, VirtualKeyCode.MENU },
                { Keys.ArrowUp, VirtualKeyCode.UP },
                { Keys.ArrowDown, VirtualKeyCode.DOWN },
                { Keys.PageUp, VirtualKeyCode.PRIOR },
                { Keys.PageDown, VirtualKeyCode.NEXT },
            };

voloxastik avatar Feb 28 '18 07:02 voloxastik

By updating below code in KeyboardModifiers.cs class, will allow you to use Enter key Winium.Desktop.Driver\Input\KeyboardModifiers.cs internal class KeyboardModifiers : List { #region Static Fields

    private static readonly List<string> Modifiers = new List<string>
                                                         {
                                                            Keys.Control,
                                                            Keys.LeftControl,
                                                            Keys.Shift,
                                                            Keys.LeftShift,
                                                            Keys.Alt,
                                                            Keys.ArrowDown,
                                                            Keys.ArrowUp,
                                                            Keys.PageDown,
                                                            Keys.PageUp,
                                                            Keys.LeftAlt,
                                                            Keys.Enter,
                                                            Keys.Tab,
                                                            Keys.Clear,
                                                            Keys.Delete,
                                                            Keys.Backspace
                                                         };

    private static readonly Dictionary<string, VirtualKeyCode> ModifiersMap =
        new Dictionary<string, VirtualKeyCode>
            {
                { Keys.Control, VirtualKeyCode.CONTROL },
                { Keys.Shift, VirtualKeyCode.SHIFT },
                { Keys.Alt, VirtualKeyCode.MENU },
                { Keys.ArrowUp, VirtualKeyCode.UP },
                { Keys.ArrowDown, VirtualKeyCode.DOWN },
                { Keys.PageUp, VirtualKeyCode.PRIOR },
                { Keys.PageDown, VirtualKeyCode.NEXT },
                { Keys.Enter, VirtualKeyCode.RETURN },
                { Keys.Tab, VirtualKeyCode.TAB },
                { Keys.Clear, VirtualKeyCode.CLEAR },
                { Keys.Delete, VirtualKeyCode.DELETE },
                { Keys.Backspace, VirtualKeyCode.BACK },
            };

shivalkar avatar Aug 14 '19 09:08 shivalkar

How do we put letters in this. For ex. if I want to press Control + H through ActionChains.How to add letters in the modifier file. Thank You

gmehta1996 avatar Aug 06 '21 06:08 gmehta1996