Is it possible to map a key press to simulate middle-click in xwindows? - mouse

I'm wondering, is it possible to somehow map a key-press event to act like a middle-key click of a mouse in Xwindows? They are diffrent devices, I know, but if there was a way to trigger a middle-button click event from a C program, it should be easy to bind a key to it using existing xwindows mechanisms.

Xevent does the trick:
http://www.isv.uu.se/~ziemann/xevent/
http://linuxgazette.net/153/misc/ziemann/xevent.c
The code compiles and runs just fine on my machine.
If you are interested as a developer: It uses the XTest extension, which is included in the X server. There is also some old, still valid documentation of that API online:
http://www.xfree86.org/current/xtestlib.html

Related

Drag and Drop Behavior on Chrome DevTools Protocol

I am trying to write a tool that open's a website and interacts with and triggers the drag/drop behavior. I am seeing Input.dragIntercepted, Input.dispatchDragEvent functions in the documentation. But when I use these functions, I am getting a ... is not a function error. Probably, I am not using them in a proper way.
How can I use these functions to trigger drag and drop behavior of the web application? I did not find any example that shows usage of these functions.
First of all, Input.dragIntercepted really isn't a function. It's an event that will be fired, but only if you enable it, using Input.setInterceptDrags with enable set as true.
This is documented both here and here.

Google smart home command for blinds

I would like to control blinds using google smart home action. How can I create commands like "turn/put my blind up/down" ? What device traits should I use? It seems OnOff trait doesn't understand up and down, can I custom it? Thanks!
You could use the undocumented (use at your own risk) device type: action.devices.types.BLINDS.
Instead you could use for traits:
On/Off: action.devices.traits.OnOff
Brightness: action.devices.traits.Brightness
In this way, you can ask Google to set a specific position, to close (in Italian it works as a turn off command, in English, I did not try yet), to turn on or to turn off. The open command instead seems to be not recognized as a turn on command.
Hope to help you and hope that Google releases soon types and traits for blinds/curtain control.
EDIT as pointed out by #robin-thoni is not documented: https://developers.google.com/actions/smarthome/guides/blinds

Simulate input of a 3D Mouse in autohotkey

I want to use autohotkey to control a program, which relys on the input of a 3D-Mouse (3DConnexion SpaceNavigator). How can I simulate a axis in autohotkey?
Maybe 3DConnexion SpaceNavigator uses same axeses as joystick? So check joystic controls here: http://ahkscript.org/docs/KeyList.htm#Joystick
If it does not helps, you can try to get the name of the control with that guide: http://ahkscript.org/docs/KeyList.htm#SpecialKeys (some explanations here: Macro Keys not Detected AutoHotkey)
By the way please write your impressions about 3D-Mouse (3DConnexion SpaceNavigator) in comments.
I think you need to get the SDK and write your own intigration...seems to be the only option, unless you figure out a way to communicate with the device by watching the usb signal

Cocoa invoke Service, do not overwrite Pasteboard

I have created a Service in Cocoa which grabs the selected Text and sends the result back to my Main App, so i can handle it there ( Couldn't find any other way to get current selection), now that the Service works and appears in the Service Menu, i tried to invoke the Service from my parent App to get current selection, after some goggling around i found this snippet:
NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
NSPerformService(#"PCB", pboard);
This one works as far as it triggers my Service, the Problem here is it redefines the NSPasteboard, so my service doesn't get the selected text, but a NIL Value Pasteboard which is blank, how can i prevent this?
And does someone know how to convert a .service bundle into an .app bundle that performs itself and sends the data and kills itself after finish?
thx for help
You want to get the text that is selected in another application, right? Probably in the front application, while your app is in the background.
For this to work, you'd have to have the Service be invoked by the front application. If you invoke it from your app in the background, it can't access the front app's text field that contains the selected text. Instead, it'll try to find a text field in your own app's responder chain (I believe – someone correct me if I'm wrong on this detail).
But for your code to run in the app's process, you'll have to inject it somehow, which is - out of security concerns - mostly prohibited by OS X, and especially with sandboxed apps.
There are ways to accomplish code injection, one that 1Password and other popular tools use it through an osax extension. But that's an entirely different topic.
Once you have your code running inside the other app's process, you should be able to copy the selected text (provided it's a Cocoa app) with [NSTextView writeSelectionToPasteboard:types:]. I haven't tested this myself, though, so this is just an assumption.

How do you set up an Optimizely test for a single-page app?

I have a single-page web app that presents a multi-step photo management "wizard", split up across several discrete steps (photo upload, styling, annotation, publishing) via a tab strip. On switching steps I set the URL hash to #publishing-step (or whichever step was activated).
How do I set up Optimizely tests to run on the various discrete steps of the wizard?
The browser never leaves the page, so it only gets a single window.load event. Its DOM isn't getting scrapped or regenerated, but just switches what page elements are visible at any one time via display: none or block, so the part I am trying to figure out is really mostly about in what way I go about the Optimizely test setup itself - it's fine (and likely necessary) if all edits get applied at once.
This thing unfortunately has to work in IE9, so I can't use history.pushState to get pretty discrete urls for each step.
There's actually several ways you could go about doing this, and which option you choose will largely depend on what's easiest for you AND how you plan to analyze the data.
If you want to use Optimizely's analytics dashboard:
I would recommend creating one experiment which will activate a bunch of other experiments at different times. The activation experiment will be targeted to everyone and run immediately when they get to your wizard. The other experiments will be set up with manual activation and triggered by this experiment.
The activation experiment would have code like:
window.optimizely = window.optimizely || [];
function hashChanged() {
if(location.hash === 'publishing-step') {
window.optimizely.push(['activate', 0000000000]);
}
if(location.hash === 'checkout-step') {
window.optimizely.push(['activate', 1111111111]);
}
}
window.addEventListener('hashchange', hashChanged, false);
Or you could call window.optimizely.push(['activate', xxxxxxxxx]); directly from your site's code instead of creating an activation experiment and listening for hashchange.
If you want to use a 3rd party analytics tool like Google Analytics:
You could do this all in one experiment with code similar to above, but in each "if" section instead of activating an experiment, you could run your variation code that makes changes to the wizard and sends special tracking information to your analytics sweet for later reporting. You'll have to do your own statistical significance calculation for this method (as Optimizely's data won't be "clean"), but this method actually works out better usually if properly configured.
Alternatively you could use the method outlined above but still try to use the Optimizely analytics dashboard by creating custom events on your experiment and sending data to them using calls like window.optimizely.push(["trackEvent", "eventName"]);
This article may also be helpful to you.
You'll probably need to do this yourself, using Optimizely's JS API to trigger actions on their end and tell it what your users did: https://www.optimizely.com/docs/api