Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hold down the keys!!! #86

Closed
Pareshwardhan opened this issue Feb 3, 2014 · 25 comments
Closed

hold down the keys!!! #86

Pareshwardhan opened this issue Feb 3, 2014 · 25 comments

Comments

@Pareshwardhan
Copy link

Hi Jarmo,
In the issue #85 i meant that i want to hold down a key .For example to select multiple folders we need to hold down the control key and click on the folders we want to select.
In my case i need to press F7 key after holding down (ctrl+shift). I hope My issue is clear to u.

@jarmo
Copy link
Owner

jarmo commented Feb 3, 2014

Please do not create new issue each time, but continue the discussion under the old one. I don't understand why this code does not work for you then:

window.send_keys [:control, :shift, :f7]

That's exactly what it is supposed to do - holding down control, shift and pressing f7 at the same time. Do you want something different to happen? You can try :left_control and :left_shift also.

@Mandeep10
Copy link

@jarmo - Can we use function press_key, to hold keys?

@jarmo
Copy link
Owner

jarmo commented Feb 3, 2014

No, because it is private method and not intended for public use. You don't need it either. Can you explain, why the suggested Array method does not work for you? What do you need to do exactly? Do you need to press f7 while holding down control+shift? If the answer is yes, then my suggested solution should work.

@Pareshwardhan
Copy link
Author

@jarmo - In my case i want to press f7 multiple times while holding down control+shift.

@Pareshwardhan
Copy link
Author

@jarmo - To be precise in my application when i hold down a (ctrl+shift) a panel appears and to navigate through that panel i need to press f7 multiple times while holding down the keys ctrl+shift.

@Pareshwardhan
Copy link
Author

12
This is the panel where i want to navigate.

@jarmo
Copy link
Owner

jarmo commented Feb 3, 2014

In that case, try like this:

window.send_keys [:control, :shift, :f7, :f7, :f7]

Or

3.times { window.send_keys [:control, :shift, :f7] }

@Mandeep10
Copy link

send_keys function uses press_key and release_key at the same time, but here @Pareshwardhan needs to use the functionality of press_key on [:control] + [:shift] and send_key on [:f7] and after selecting a particular item from panel, release_key[:control] and [:shift]

@jarmo
Copy link
Owner

jarmo commented Feb 3, 2014

Ok, can you tell me step by step how would you do it manually with your hands using real keyboard. Currently i'm not sure i understand it correctly. Are you saying that control+shift+f7 will open up the panel and you have to select something from there with your mouse and only after that you can release control+shift?

@Mandeep10
Copy link

Yes you are somewhat correct. But f7 key need to be pressed separately, for selecting purpose. control + shift should be pressed and hold first then in order to navigate through options, f7 key will be pressed (not mouse). And after selecting a particular option (while navigating) through f7 key, need to release the control + shift.

@enkessler
Copy link
Collaborator

It sounds like the desired use case IS to be able to hold down on a key for an arbitrary amount of time before releasing it (as a separate command so that other stuff can be done in between the two). Is there a reason not to have a public equivalent to #press_key?

@anuragkhera
Copy link

@jarmo -Hye i want to perform multi select functionality, for that i am using shift down + down arrow key but it is not working out, how can i resolve it?

@jarmo
Copy link
Owner

jarmo commented Feb 4, 2014

My provided examples does just that - keeps control+shift pressed while pressing f7.

What happens if you try the solutions i provided above? It is quite hard (or rather impossible) to help if you don't give any feedback at all.

@Mandeep10
Copy link

The examples you have provided does not work here. It does not have control on selecting a particular option from the panel. Your example press all these 3 keys [control+shift+f7] parallelly, this is not the requirement.

@jarmo
Copy link
Owner

jarmo commented Feb 4, 2014

How come? You said that you need to press control+shift and keep them pressed while pressing f7 - this means that you press them all at the same time. Do i misunderstand anyhow?

@Mandeep10
Copy link

Yes you misunderstand. We need press_key functionality, as simple as that.

@jarmo
Copy link
Owner

jarmo commented Feb 4, 2014

So you're saying that while holding down control+shift and pressing f7 at the same time, then nothing happens? Or does something happen and this is not the expected behavior? Can you tell me exactly what happens and what do you expect to happen?

I don't understand how is it different to hold down control+shift then press f7 and release control+shift rather than hold down control+shift+f7 and then release them. Seems to me like a usability failure in your application when that combination does not work the same as the former.

Since RAutomation is written in Ruby then you can execute private methods as well with some hacking.

Untested:

window.activate
win32_window = window.instance_variable_get :@window
win32_window.send(:press_key, RAutomation::Adapter::Win32::Keys.encode(:control))
win32_window.send(:press_key, RAutomation::Adapter::Win32::Keys.encode(:shift))
window.send_keys :f7, :f7, :f7
win32_window.send(:release_key, RAutomation::Adapter::Win32::Keys.encode(:control))
win32_window.send(:release_key, RAutomation::Adapter::Win32::Keys.encode(:shift))

This is not part of the public API, because it does not make sense to have a functionality like this and it might cause many problems - some keys might be left pressed and will cause problems. As i said above - this seems to be an usability issue. Also, the API has been "stolen" from webdriver API, which also does not support functionality like this (at least i'm not aware of).

@enkessler
Copy link
Collaborator

Granted, the application in question could be a nightmare when it comes to usability. But is that a good reason to not be able to automate it?

If accomplishing some goal in an application requires the user to hold down ctrl+shift, click on a nav link with the mouse, press the page down key a few times to bring an item into view, press F7 to pick that item, and then finally release ctrl+shift...then, yes, that application has a poor user experience. But automation is about relieving a human of the burden of doing some task. The silliness of the task should factor into it only if relieving said burden places one that is just as large on the automation tool. In this case, the burden on the automation tool is just having a public #press_key and #release_key. That's not too much to ask.

Having a similar look and feel to the webdriver API is not a bad idea. If there are analogous actions that both APIs perform then it is a nice touch to have them line up so closely. However, that's not reason to limit ourselves to the webdriver API. Just because they -don't- doesn't mean that we -can't-.

@leviwilson
Copy link
Collaborator

I'm with @jarmo on this. I wouldn't want to expose our privates to expose an API to accommodate the exception rather than the rule. Leaving something in a #press_key state would not be a good idea.

If he wants to have it, that's what monkey patching is for :-)

@Pareshwardhan
Copy link
Author

@leviwilson If there is a functionality of #press_key then there is #realease_key to restore the key into initial state. isn't it??

@leviwilson
Copy link
Collaborator

Did you try what was suggested up above?

@Pareshwardhan
Copy link
Author

yes i tried but i got the error message "NoMethodError: undefined method `reduce' for :control:Symbol"!!!!!

@jarmo
Copy link
Owner

jarmo commented Feb 5, 2014

Yeah, Keys.encode needs an Array. Sorry!

So, it's:

window.activate
win32_window = window.instance_variable_get :@window
win32_window.send(:press_key, RAutomation::Adapter::Win32::Keys.encode([:control]).first)
win32_window.send(:press_key, RAutomation::Adapter::Win32::Keys.encode([:shift]).first)
window.send_keys :f7, :f7, :f7
win32_window.send(:release_key, RAutomation::Adapter::Win32::Keys.encode([:control]).first)
win32_window.send(:release_key, RAutomation::Adapter::Win32::Keys.encode([:shift]).first)

Next time please provide us with your code and backtrace. It would be much more helpful :)

@Mandeep10
Copy link

Thanks @jarmo and @leviwilson, now its working. :)

@Pareshwardhan
Copy link
Author

Thank u!!!! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants