How to create a Windows application that: detects current program and sends shortcuts - windows

I would like to create an application for Windows that is visible in the system tray and can detect the current open window. The application that I want to make should also be able to "press on the users keyboard": sending out keyboard shortcuts to the current open window/application.
How would I go about doing this? What programming languages/tools would be useful?
Best would even be if it is portable to Mac, but this is not a must.

Portability: Not very likely you can find anything that is cross-platform for this.
For Windows: AutoIt. Does everything you want and a lot more.
For Mac: Applescript (standard component of OSX) can probably do this, but I could be wrong about that. I do have a Mac, but I never had a reason to play around with this sort of stuff.

Related

Windows explorer monitors directory changes in a tricky way?

I have a sandbox system redirecting file modifications by hooking Ntxxx file system APIs. An interesting thing is, if i move files in Notepad->File/Open dialog in my sandbox, e.g. from desktop\a.txt to desktop\b\a.txt, the a.txt file on real desktop just disappears, and it comes back after i refresh real desktop by pressing F5. actually there is no change in desktop folder at all, because all changes are directed. I know that most apps use API like ReadDirectoryChanges to monitor changes, but apparently explorer is doing something different. I tried tools like https://directorymonitor.com/, they did not observe any changes on desktop. I guess SHFileOperation internally interact with explorer somehow, but who knows details and how can i prevent this notification? It is really strange for users to see a file disappearing while it is actually still there.
windows calls windows_storage!SHChangeNotify instead of that one in shell32. Why does Windows have two copies of same API, are they different?

On macOS how can I open a gui .app hidden or off screen?

I have a cross platform need to open a gui application programmatically, but keep it hidden from the user. Effectively, I want a command line driven interface to act as a wrapper over this gui app, and insulate the end user from seeing or interacting with it. The program is from a third party, I did not write it, and I can't edit it.
I can do this one way or another on Windows, on Linux, and (in theory) on older versions of Mac, but not the most recent ones. On Windows, I can use the native api ShellEx with a hide window parameter. It's very easy and straight forward. In Linux, I can can render a gui app to a virtual frame buffer (using xvfb).
On macOS, the open command has a --hide and --background option, but they don't have any effect (at least on this app...)
I tried changing the plist file and found that LSUIElement will hide the app from the docker, but it still shows up on the screen. LSUIPresentationMode=4 or 3 OUGHT to work for exactly this, but apparently that doesn't do anything anymore as of a few os versions ago...
I tried the approach of moving the .app off of the screen with AppleScript. That works, but you have to manually grant permissions for such a thing to occur via System Preferences. In prior versions of Mac, those permissions could be twiddled on the fly via sqlLite (so long as you had sudo rights), but now they blocked that too. You can only pull that off apparently through a process of disabling "SIP" and forcing a reboot. That is totally outside the realm of what I want.
I've tried using the xvfb approach on Mac (jumping through hoops to acquire the binary they use to include stock, and now dropped), but I'm not having luck with that. I don't think it's possible to direct a mac .app to another display is it? A .app does not render on X11 by it's nature right?
What other clever ways might there be to hide a third party app on a mac? (and that still works in most recent os versions!)

How can I lock down a Mac to exhibit one website?

I'm currently working on a website that will be in an exhibition soon. Users will have a keyboard and mouse in front of them, so I need to lock down the machine to be restricted to just one website. Guided Access mode on iOS is a perfect example. I wish Apple had an OS X version for this reason.
I'm currently trying parental controls but it seems to be quite buggy/not responding to my preferences. I'd really love to just have Chrome or Safari locked to fullscreen somehow so users can't exit the browser/redirect to another website.
Thank you in advance!
I'm thinking you could put Chrome in kiosk mode(can't change website) then change the shortcut keys for exiting out of fullscreen mode if you can on a Mac, and maybe having another desktop and monitor for emergencies. I would have made this a comment but I can't :P This isn't really an answer, just a suggestion. It would really be easier on another OS to do the stuff above.
Recently used 'Web Kiosk' software for exactly this purpose: https://www.macproline.com/webkiosk
It has a lot of options for locking down the machine, both in terms of web sites visited, and disabling key commands, preferences, switching apps, quitting apps, etc.
When searching for a solution for this, I was surprised how few options there were. That said, I would give this a look.

Is there a way to capture console controls (keyboard/mouse/remote) in OSX so they can be replicated on another machine?

I need to mirror GUI console activity happening on one Macbook so that it is duplicated on a second identical Macbook.
The idea is to control an application that will run on two Macbooks simultaneously. The application is sort of a presentation with two variations in content, but identical controls. Think of it as two versions of PowerPoint presentation with some slides that are different.
I'm thinking that it may be possible to capture the keypresses and mouse events on one Mac, then use RFB protocol to send these across the network to the other Mac. I'm looking at rfbproxy and rfbplaymacro, but these are somewhat inelegant hacks, and any solution built on these will also be a bit of a hack. And of course, I'd prefer to avoid a solution that requires me to compile and perhaps debug software that hasn't been touched in half a decade. :-)
I could conceivably use Cliclick or xdotool (from MacPorts) to initiate console events on the "slave" Mac. But then I don't know what I'd use to capture the events on the "master". Or would an xdotool-based solution require that both Macs be slaves, and then use some other device as a master?
Input devices could be a presentation mouse, an Apple remote, or in a pinch, the keyboard of on of the Macbooks or even a third device.
Can you suggest tools? Or is there another strategy I haven't thought of?
If the computers are in the same room, a single Apple Remote can control both Macs as long as the remote is not paired to either one. I'm assuming you need a solution that will work over any arbitrary distance, though.
Have you considered AppleScript? It's pretty good at sending keystrokes to ssh-accessible Macs. The receiving application doesn't even need to be aware of AppleScript (i.e. scriptable). You'll just have to be sure GUI scripting is enabled on the targets by checking the Enable access for assistive devices option in the Universal Access system prefs panel.
Here's an example of a shell command that will send a keystroke to the frontmost app via applescript:
osascript -e "tell application \"System Events\" to keystroke \"a\""
If you set up key-based ssh auth between the master and slaves you can simply tack ssh onto the front of this command:
ssh slave osascript -e "tell application \"System Events\" to keystroke \"a\""
For elegance, you could wrap any number of desired keystrokes into a menu-based bash script and run it from a third computer.
I have tried to synchronise systems like this that are NOT Macs a few years ago using rfbproxy and rfbplaymacro which you already know about. The systems were both X terminals running at the same resolution. We still had problems because of different font size settings putting application controls in different places, but the basic VNCiness of the solution seemed to work just fine.
That said, if you want to write a stand-alone application to send stuff using osascript or cliclick or xdotool, and you have a wii, you might get some joy from DarwiinRemote.
Kindof convoluted, but you could use clusterSSH for OSX to start shell sessions from a third machines master window, and then send commands to the two slaves. This could be paired with a screen control utility similar to the ones you list above, another of which is pymaCursor.
If everything could instead be recorded in advance, you could try good ol' applescript/automator recording, or a newer project like sikuli - http://sikuli.org/

Synergy between mac and pc change mac hotkeys

Synergy is a program that enables you to use the same mouse and keyboard in two computers. I have a PC and mac connected directly with an Ethernet cable therefore the connection is great and it seems as if there is only one computer.
I am developing an iPad application and the only software that I have found that supports iwebkit for CSS is Expresso. I use that to edit my CSS files in the mac and I use dream weaver on my PC to edit PHP, HTML and JavaScript files. The only problem is that I am constantly using both computers to develop the application and its very frustrating using different shortcut keys for each computer. It would be very nice if I could use the same hot-keys on both computers.
So far I have tried:
Changing the modifier keys in the keyboard section under system preferences in the mac. That works but just with the keyboard from the mac not with the keyboard that I am using with synergy that controls both computers.
Creating applescripts that what they do is to send a shortcut key then compiling them and saving them as an application. After they are saved as an application I go to system preferences and try to run them with a different shortcut key. when I create that shortcut key system preferences crashes and closes without saving the changes.
Creating shortcut keys in synergy which it works but only in one computer. Synergy will always send the same keystroke regardless on which computer you are using.
Lastly I have tried looking for "IronAHK" which in a lot of posts people say it modifies the mac hotkeys but I have not been able to find it for the mac.
Is there a way to have the same universal access keys across my machines?
THe following article was very helpful for me (working from a Mac, controlling a PC):
http://www.nextofwindows.com/how-to-properly-map-keyboard-between-mac-and-pc-when-share-mouses-with-synergy/
Step 1: Configure Server
Step 2: Double-click on the PC (or Mac if the Server is a PC)
Step 3: Toggle the key Ctrl and Super to mirror each other
When adding a new computer in synergy you can change command and control keys. Here is an example in windows. I was not able to find it because synergy place this in a location where I never thought I could find it.
Now I can use control + c to copy files both in the mac and in the pc and most of the command such as control + a to select everything etc. To fix the other issues so that I can use 'home' to go to the beginning of the line for example I use the program provided by Evan Moran which was the first answer in this post.
For the mac I use KeyRemap4MacBook. It is pretty good for being free.
That said, consider using different source editors so that you can code only on one system. This will make your life a ton easier. Dreamweaver is not necessarily the best. Visual Studio is pretty good on Javascript, CSS, and HTML, and their express versions are free.
If all you need is syntax highlighting EditPlus is great on the PC and will work on all languages you mentioned. If you need to stay on a mac then TextWrangler is great as a basic source editor. Both have free trials. Good luck!

Resources