Watir rautomation mouse move does nothing - browser

I'm trying to get a hidden element visible. I've tried every mouse event and element selector I can find in Watir. So I'm trying to use RAutomation code that's already within watir. But it seems ineffective.
require 'watir'
#browser = Watir::IE.new
#browser.goto 'samplesite.com'
#browser.rautomation.mouse.move({:x=>210,:y=240})
From this I get the browser to raise to the top, and the console replies nil. But the mouse hasn't moved. Then when I proceed to do
#browser.rautomation.mouse.click
I get a response of 2... which I take as a success of the click. I need to be able to move the mouse to this coordinate.
#browser.rautomation.adapter
returns => :win_32
Can I set it to :autoit in an already established instance of Watir?
Help please.

So, what you're saying is that the mouse does not move at all?
Try this code:
mouse = #browser.rautomation.mouse
puts mouse.position.inspect
mouse.move :x => 100, :y => 100
puts mouse.position.inspect
What is the output?
To use AutoIt adapter, you can do this:
mouse = RAutomation::Window.new(:adapter => :autoit, :hwnd => #browser.hwnd)
mouse.move :x => 100, :y => 100

Related

How to detect a button click and a normal click in bevy

I'm making a tower defense game in bevy and I'm having problems with placing a tower. So basically I want to make it so that when you click one of the buttons (each one spawns a different tower) an asset/sprite of the tower should follow your mouse and when the mouse is clicked AGAIN it should spawn the tower.
Currently my program registers the button click, but it goes into 2 ifs so when the button is clicked it automatically spawns a tower somewhere (not even below the button) without waiting for the user to click again. So the Interaction::Clicked only checks if the button was clicked, but doesn't grab the mouse click event, it only reads it so therefore if the mouse is clicked for a longer period of time (human click) the code will go into the second if and spawn the tower (I don't know why it spawns it where it is on the picture below). How can I fix this? Picture:
Towers spawning in some random place. First button spawns them at around (200, 0, 0)
Code:
fn tower_button_interaction(
mut commands: Commands,
windows: Res<Windows>,
mouse: Res<Input<MouseButton>>,
assets: Res<GameAssets>,
interaction: Query<(&Interaction, &TowerType), Changed<Interaction>>
) {
let window = windows.get_primary().unwrap();
for (interaction, tower_type) in &interaction {
match interaction {
Interaction::Clicked => {
info!("Spawning: {tower_type} wizard");
// Upon clicking the mouse, spawn the selected tower on the map
if mouse.just_pressed(MouseButton::Left) {
if let Some(position) = window.cursor_position() {
spawn_tower(&mut commands, *tower_type, &assets, position.extend(0.));
}
}
}
Interaction::Hovered => {}
Interaction::None => {}
}
}
}
I also tried changing the if mouse.just_pressed(MouseButton::Left) to if matches!(interaction, Interaction::Clicked), but the same thing happened.

Node blessed library: how to set a single character?

Maybe I miss something from the documentation. Blessed.js (the curses-like library for node) comes with any kind of boxes / input / output / mouse utilities and seems wonderful, but how can I set a single character on the screen?
For example, having created the screen like this:
const blessed = require('blessed');
const screen = blessed.screen({
smartCSR: true
});
how can I use screen to display, say, the character 'A' in position [4, 5] (fuorth character of the fifth row)?
Thanks
Use their text widget. Create one and add it to the screen.
let anA = blessed.text({content:'A', top:4, left:5}) // create a text widget
screen.insert(anA) // add it to the screen
screen.render(); // render the screen
I've barely worked with it, there might be a simpler way. But forgetting to render is what me got most of the time.

how to check if you cklicked (with your mouse) in an defined area in python/pygame

I want to check if you clicked in an defined area, for example an area from 0,0 to 400,40 (pixel coordinates). I have this:
x = 0
y = 0
(mouse_posx, mouse_posy) = pygame.mouse.get_pos()
press = pygame.key.get_pressed()
if mouse_posx > x and mouse_posx < x+400 and mouse_posy > y and mouse_posy < y+40 and press != 0:
function()
I get no error but it does nothing.
Can someone tell me what i am doing wrong?
What you want to do is have your program listen for events. Once the event of mouse button is triggered, then record the mouse position. Then verify if the mouse position is inside the box.
Pygame mouse
Oh and also, I dont think the event of mouse button gets recorded in the > pygame.keys.get_pressed <. I believe the pygame.keys.get_pressed is just for the keyboard.
I may be wrong, im using my mobile and dont have a computer with me.

Hold-Hover drop down menu Delay Time

Im creating a drop down menu and i want to know if there is anyway to implement the following:
I need to keep the sub-menu open for like 1 sec if the user moves the mouse away from the tab he selected. Much likely like in current intel web page www.intel.com , here u hover over menu, but if u take the mouse away from the tab or the sub-menu is opens it takes a few to hide the sub menu.
Im using .mouseover from jquery to show the menu (a div) but i cant find a way to make it stay for a few moments.
Thanks in advance
This may be of service
What is the JavaScript version of sleep()?
If you want to do something in the interim setTimeout() takes the arguments as shown where continue execution is another subroutine. If you just want this one tab to work this way have mouseover call doStuff and set a boolean (e.g. mouseStillIn) to TRUE. When the mouse exits set this boolean to FALSE, call a recursive function everytime mouseStillIn is TRUE.
e.g.
var mouseStillIn : boolean = false;
function MouseIn()
{
mouseStillIn=true;
CheckMouse();
}
function CheckMouse()
{
if(mouseStillIn)
{
setTimeout(CheckMouse, 1000);
}
}
function MouseOut()
{
mouseStillIn=false;
}

How do I use Watir to download a file to a specific location in IE9

In the older versions of IE, there is a popup window.
In IE9 it's a funny looking bar on the bottom.
Anybody had tried anything that works yet?
The only way for now is sending TABs.
For example with Watir and RAutomation
ww = Watir::IE.attach(:url, /1.1.1.127/)
#Click on download link
ww.link(:text, /Download_link/).click
#Click on 'Save As' in the 'funny looking bar on the bottom'
wrauto = RAutomation::Window.new(:title => ww.title)
wrauto.send_keys("{TAB}")
wrauto.send_keys("{TAB}")
wrauto.send_keys("{DOWN}")
wrauto.send_keys("{DOWN}")
wrauto.send_keys("{ENTER}")
#popup window to save
w = RAutomation::Window.new(:title => /Save As/)
#Direction that you going to save
w.text_field(:class => "Edit", :index => 0).set path_direction
w.button(:value => "&Save").click
RAutomation::Window.new(:title => /complete/).button(:value => "Close").click

Resources