jarmo / RAutomation

RAutomation
MIT License
100 stars 33 forks source link

hold down the keys!!! #86

Closed Pareshwardhan closed 10 years ago

Pareshwardhan commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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

jarmo commented 10 years ago

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 commented 10 years ago

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

Pareshwardhan commented 10 years ago

@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 commented 10 years ago

12 This is the panel where i want to navigate.

jarmo commented 10 years ago

In that case, try like this:

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

Or

3.times { window.send_keys [:control, :shift, :f7] }
Mandeep10 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

@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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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

jarmo commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

@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 commented 10 years ago

Did you try what was suggested up above?

Pareshwardhan commented 10 years ago

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

jarmo commented 10 years ago

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 commented 10 years ago

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

Pareshwardhan commented 10 years ago

Thank u!!!! :)