Simulate mouse presses (BUTTON 4 and 5) - mouseevent

I'm trying to create a single file in BAT (Windows Command Prompt) to simulate a Mouse Back and Mouse Forward event (which is in fact just pressing down mouse button 4 and 5). I can't find anything on the internet on how to simulate these exact events. Most of them are about clicking the left mouse button but that's not what I need.
The program should be as simple as possible as I do not want heavy coding on this one. It should be straight forward and I hope one of you could help me out. Is this even possible (with BAT)?
The reason for this is that Logitech Gaming Software wrongly executes the back and forward buttons' up event twice, which results in annoying behaviours while for example browsing a webpage and trying to go back one page. It would then go back two pages.

Ok, I've been a little too quick with my question but it might help others. If you have the problem of your Logitech mouse doing double forward or backwards on browsers (Chrome, IE etc.) and in Windows Explorer please try the following.
First of all, you'll want to remove the currently mapped buttons. Be sure to select the desired profile first! So go over all three buttons (MOUSE 3, MOUSE 4 and MOUSE 5 (middle, tilt left, tilt right)) and remove their current mapping. By default (generic buttons) it will be "Middle click", "Back" and "Forward".
Now right click the profile at the top and select "Scripting". This is open a new window in which we can do some very advanced but still easy coding. Clear the whole thing and paste the code you find below in there. Press "Script" >> "Save" at the top of the window to save it and enjoy the working glory! You can easely test this by right clicking the profile again and selecting "Test profile". Now press any of the three buttons and you should get the outcome we want (down and up event only once on those exact buttons).
If you want to do some coding of your own feel free to change the script! The actual numbers to each mouse button can be found by clicking "Help" >> "Scripting API" at the top, along with some handy documentation. Keep in mind that you'll have to do this for every profile you desire. Doing this on the Default Profile seems the most reasonable for browsing.
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
OutputLogMessage("Pressing back button\n");
PressAndReleaseMouseButton(4);
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
OutputLogMessage("Pressing forward button\n");
PressAndReleaseMouseButton(5);
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 3) then
OutputLogMessage("Pressing middle button...\n");
PressAndReleaseMouseButton(2);
end
--OutputLogMessage("event = %s, arg = %s\n", event, arg);
end

Related

SAP GUI scripting - Button press fails

I am using a macro in an Excel file that runs the SAP GUI. There is a step where, when I click a button in SAP there will be another window that pops up.
For that I have written a code like this:
session.findbyid("wnd[0]/XX/btnXX").press
session.findbyid("wnd[1]/XX/btnXXX").press
There is a button (btnXXX) in the window (wnd[1]). But when I execute this query, I am getting an error object not found for findbyid.
When I keep the break point and execute it, it is throwing error on 2nd line in the above code. I try to pick the activewindow.name and it shows wnd[0] still. Here the issue is wnd[1] is not getting opened.
Does somebody know why the 2nd "button press" doesn't work?
You should be able to replace all mouse clicks with keyboard strokes.
Replace:
session.findbyid("wnd[0]/XX/btnXX").press
With:
session.findById("wnd[0]").sendVKey(N)
Where N is the linked hot-key ID.
To get the exact command, use SAP script recording and only use the keyboard to transition between views and windows. The easiest way to determine how is to hover your mouse over the buttons you would normally click to learn the hot-key then record the hot-key.
Note 1) So far I have found that btn[XX] always maps to sendVKey(XX), but I can't be certain this is always the case.
Note 2) sendVKey always appears to be referenced off the window (wnd[Y]) even if a button is another layer down (/tbar, /usr, etc.).

Can I ControlClick a link or object if there's no Control information?

I'm using AutoIt to automate the handling of a proprietary Windows EHR application, and it looks like the creators of the application wrote it without adding classes, IDs, or names to any of their links or menu items inside the application. The application I'm trying to automate is PrimeSUITE by Greenway Health.
I've gotten it to work by using MouseClick and adding coordinates, but that only works so long as the user doesn't move the Window. I'd like to use the more reliable ControlClick method to send click commands (I don't think there's a third way to send click commands in AutoIt).
Luckily, there's a keyboard shortcut built into the application to open the menu item I want in a new window. This is how I'm currently having to access the menu item:
WinActivate(": PrimeSUITE -- #CompanyName# -- PRIMESUITETEST")
Send("{F7}")
WinActivate("Report Selection -- Webpage Dialog")
WinWaitActive("Report Selection -- Webpage Dialog")
At this point I have to rely on the window's position on the screen not moving, so that I can send MouseClick coordinates (whose origin point begins in the top-left corner of my monitor screen, rather than the current active Window's top-left corner).
I'd like to be able to activate it somehow like:
ControlClick( ": PrimeSUITE -- #CompanyName# -- PRIMESUITETEST", "Reporting", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "left", 1, 491, 15)
So that the coordinates are relative to the active window's top-left corner rather than the monitor screen's top-left corner.
For context, this is what I see when I am hovering in the application's main window (note, the application is run from the desktop; it's not a web app accessed in IE), no matter which part, regardless of whether I'm in a blank space or hovering a link/menu item:
But as soon as I hover over a menu item and then move the cursor to a submenu item, I get this:
Here is the Tree View of what Inspect.exe found:
Am I going to be stuck with the MouseClick method via screen coordinates, or is there a way to use ControlClick or some other way to send clicks programmatically?
Even though it is a desktop application it is using IE objects. You can attach to it with _IEAttach and then use _IEAction to click on objects like your menu.
Here is an example of how to attach to PrimeSUITE (you may need to change the window title).
#include <IE.au3>
$hWin = WinGetHandle("PrimeSUITE")
If WinExists($hWin) Then
$oIE = _IEAttach($hWin, "embedded")
_IELoadWait($oIE)
MsgBox(262144, "", _IEBodyReadHTML($oIE))
Else
MsgBox(262144, "", "Window not found.")
EndIf
Once you are attached you can look at the HTML to see how you want to automate the program. You have a lot of IE functions besides _IEAttach that you can use. For example: _IELinkClickByText, _IELinkClickByIndex, _IEFormElementSetValue, and _IEFormElementOptionSelect.

Mouse button hotkeys only work once, not continual

I need to make an AutoHotkey script that performs some action when and while the mouse button is pressed, then finishes when the mouse button is released.
For (a very simplified) example:
LButton::
MouseGetPos x,y
MsgBox %x%-%y%
LButton Up::MsgBox Foobar
Replacing the LButton with a keyboard key (e.g., LWin) makes it work correctly and moving the mouse cursor updates as expected while the key is held down, but using the mouse button only performs the LButton action one time. I need the hotkey action to continue occurring until the button is no longer being held.
After a bunch of query-term tweaking, I found a page that gives sample scripts for autofire.
I wasn’t sure that was what I wanted (even though it made sense) because as I said, the sample script already works just fine for keys, but I gave it a shot anyway. I tweaked the sample a bit and now it works as desired. (Actually, it is very similar to a solution I had already been using, but now it absorbs the button event, which solves the underlying problem that I led me to trying the aforementioned script.)
Hopefully I picked good keywords in this post so that anyone else who finds themselves in the same situation can find the/a solution faster than I did.
#SingleInstance,force
CoordMode, Mouse, Screen
LButton::
While GetKeyState("LButton","p") {
MouseGetPos x,y
Tooltip %x%/%y%
Sleep 75
}
return
LButton Up::
Tooltip Foobar
return

AutoHotkey background clicking and typing

I'm trying to use AutoHotkey to do some background clicking and typing while I'm doing other stuff in the foreground.
I've gotten used to Send but I haven't figured out how ControlSend works yet. Can anyone give me an example using something simple like MSPaint in the background and changing the color of paint.
Is this even possible to do? I have a script currently that pulls from daily Excel report, assigns each row a variable and punches it into another program, but I need it to click and type some canned messages as well.
The first question should probably be why use mouse control? Keyboard control is sooo much easier and often more reliable. What is it that you try to do with a mouseclick that can't be done through keyboard commands?
Also mouse clicks normally activate the hidden app.
OK you wanted an example...
+Home:: ;Shift + Home = stop/start radio
SetControlDelay -1
ControlClick, x384 y143, Radioplayer
Return
Here i click on the play/pause button of a streaming radioplayer. The mouse coordinates are found with the aforementioned Windows Spy and the title of the browser (you might have to use SetTitleMatchMode). Why not look at the AutoHotKey Command list and check out the examples there....
Let me know if this is (roughly) what you are looking for....
SendMode Input ; Recommended for new scripts
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2 ; A window's title can contain the text anywhere
!F1:: ; Press Alt F1 to execute
IfWinExist, Microsoft Excel
{
ControlSend ,, 1000{Enter}{Down}, Microsoft Excel
}
return
Here is some code I used to first record the mouse position (relative mouse position did not work since the window was tiled and the click position could be changed by moving the tiles). Immediately after that I click the mouse at the recorded position (and redo this later on in the code as well).
SplashTextOn, 200, 100, Script Preparations, Please Click on the Person `"Search Term`" link (1) in SAP. ; Show new instructions to the user
WinMove, Script Preparations,, (A_ScreenWidth/2)-150, (A_ScreenHeight/2)-200 ; Move the text instructions window with the name "Script Preparations" 150 pixels right of the center of the screen and 200 pixels up SoundBeep 600, 300 ; Wake up user
; From here on the left mouse button will temporarily be disabled
Hotkey, LButton, on ; Turn Left Mouse Button OFF, to capture the Mouse click
KeyWait, LButton, D ; Wait for LeftMouseButton click Down
MouseGetPos, xposS ,yposS ; Store the position where the mouse was clicked (Search Box)
MouseClick, left, %xposS% ,%yposS% ; Perform the mouse click on the captured mouse location
Hope this helps.
In your situation, I assume that you only need to determine the mouse position with Window Spy.

Closing frontmost window in Cocoa in an app without a menu bar

I am building a StatusBar App in Cocoa, therefore I have no menu. Having no menu implies not having a "File > Close" menu item, which normally listens to the shortcut "Command + W".
From my StatusBar App the user may open a window to change the preferences and that's where I'm running into problems: The user can only close the window by pressing the red dot with the mouse. However, like alle applications I want to support the "Command + W" shortcut as well.
At the moment I see two possibilities to solve this issue:
Place an invisible button on the window which listens to the shortcut.
Add an application-wide listener for the shortcut and contact the window manually.
Both solutions feel like a misuse of the system. The first solution can lead to unexpected behaviour (the window closes if the user hits the invisible button by chance) and the second solution will still result in a beep, since the window does not know that it handles such a shortcut.
Is there an elegant way to solve this problem? Since the view should know what to do, a solution with just Interface Builder would be perfect. If there is no elegant way, is there a way to enhance the solutions mentioned?
Thanks in advance!
If you put a File > Close menu item in your MainMenu nib, the shortcut will work, even though the menu isn't visible.
If you choose to implement an app-wide listener for the shortcut instead, you can get rid of the beep by returning nil from the block, so that the original event doesn't get passed on.