Sticky key activation (shift 5 times) doesn't work by hotkey ::Send {LShift 5} - accessibility

I would like to activate sticky keys by pressing 1 button, instead of pressing shift 5 times, which is the default way.
If I were to do
F9::Send {LShift 5}
pressing F9 will yield nothing.
I also tried
F9::
Send {LShift}
sleep 50
Send {LShift}
sleep 50
Send {LShift}
sleep 50
Send {LShift}
sleep 50
Send {LShift}
sleep 50
return
Are there any reasons as to why it's not working?

While there is most likely a way to do a dll call or something complicated, it is also possibly to program similar functionality using AutoHotkey. This would also avoid the sticky keys prompt, and you can do a traytip instead.
stickykeys = 0
F9::
stickykeys:=!stickykeys
Traytip, Sticky Keys, % (stickykeys) ? "On" : "Off"
return
#If stickykeys
*$Shift::
key = 0
Input, key, L1 M
SendInput {Shift Down}{%key%}{Shift Up}
return
*$Ctrl::
key = 0
Input, key, L1 M
SendInput {Ctrl Down}{%key%}{Ctrl Up}
Return
*$Alt::
key = 0
Input, key, L1 M
SendInput {Alt Down}{%key%}{Alt Up}
Return
#If
F9 simply toggles sticky keys on and off.
Note: This is using AHK_L which supports #If

SPI_GETSTICKYKEYS:=0x003A
SPI_SETSTICKYKEYS:=0x003B
SKF_STICKYKEYSON:=0x1
VarSetCapacity(STICKYKEYS,8) ; DWORD cbSize;DWORD dwFlags;
NumPut(8,&STICKYKEYS,"UInt")
F9::
DllCall("SystemParametersInfo","UInt",SPI_GETSTICKYKEYS,"UInt",8,"PTR",&STICKYKEYS,"UInt",0)
dwFlags:=NumGet(&STICKYKEYS,4,"Uint")
If (dwFlags & SKF_STICKYKEYSON)
dwFlags-=SKF_STICKYKEYSON
else dwFlags|=SKF_STICKYKEYSON
ToolTip % "STICKYKEYS are " (dwFlags & SKF_STICKYKEYSON ? "ON" : "OFF")
SetTimer,ToolTipOff,-1000
NumPut(dwFlags,&STICKYKEYS,4,"UInt")
DllCall("SystemParametersInfo","UInt",SPI_SETSTICKYKEYS,"UInt",8,"PTR",&STICKYKEYS,"UInt",0)
Return
ToolTipOff:
The code is from the Autohotkey forums at http://www.autohotkey.com/community/viewtopic.php?f=1&t=93650
A note for anyone wanting to use the code: I think you have to put it at the top of your script for it to work. In my script of hotkeys, placing it in the middle, and pressing F9 to activate sticky keys caused some weird things to happen: The cursor jumped around, some folders were launched, the script exited, etc. I'm guessing that it activated other hotkeys nearby?

Related

watchkit: sleep -- can the isIdleTimer be changed/disabled?

I'm looking for an equivalent to the following iOS option: UIApplication.shared.isIdleTimerDisabled = true
That is, I'd like my Watch application to stay alive longer than the quick "sleep"/idle time that gets triggered when you don't move your wrist.
Its not perfect -- the watch will still sleep with inactvity, but this extension does slow it down by tricking the watch do ignore a 'wrist-down' or 'wrist-move' motion: Add the WKExtension inside one of your #IBActions:
#IBAction func mySlidefunction(){
// ... etc ...
WKExtension.shared().isAutorotating = true;
// ... etc ...
}

tk2combobox: how to control response to up/down arrow keys

I've got a UI in R using tk2combobox.
If the control has focus, and I hit the "down-arrow" key, it expands the list, rather than changing the selection.
It doesn't actually change the selection until I arrow down and hit "enter" or click with the mouse.
Is there any way I can get it to change the selection immediately with the arrow key?
This is how you do it in Tcl. I could not get the very first
key-down to work, as somehow the interactions in bindings caused
the second key-press to disappear.
package require Tk
proc ::lbarrowhandler { w } {
set currselidx [$w curselection]
regsub {\.popdown\.f\.l$} $w {} cb
$cb current $currselidx
return -code ok
}
set ::x cc
ttk::combobox .c -values {aa bb cc dd ee ff} -textvariable ::x
pack .c
bind ComboboxListbox <<ListboxSelect>> +[list ::lbarrowhandler %W]
Edit:
Another possibility is to use the ttk::spinbox with the -values option.
I don't know your exact use case, but this will give the user a limited
selection of values. The disadvantage here is that the complete list
is not visible.
set ::x cc
ttk::spinbox .sp -values {aa bb cc dd ee ff} -state readonly \
-wrap true -textvariable ::x
pack .sp
The -state readonly prevent the user from typing anything in, and the
-wrap option will have the arrow controls wrap from end to beginning and
vice-versa.
References: http://www.tcl-lang.org/man/tcl/TkCmd/ttk_spinbox.htm

Assigning a Hotkey in Autoit

I want to use space bar to "click" a specific button in a window with autoit (without focusing the program?), like a "start" button in a game.
I tried to use ControlClick function but It's doing nothing by the way. I think i'm doing something wrong.
HotKeySet( "{space}", "MyFunction")
Func MyFunction()
ControlClick ( "title", "text", controlID [, button = "left" [, clicks = 1 [, x [, y]]]] )
EndFunc
Is it something like that?
Your way doing it is good. You are missing the title and the controlID of the ControlClick function. The 1st and 3rd parameter should be set to the title of the window and the control ID of the control.
To get those use the AutoIt tool that comes with autoit installation.
Set those properly and the code should work.
U can use it like this.
First start AutoIt info program to get desired coordinates ( place where u want to click ), use finder tool to get coorinates of mouse and edit it in a script.
So when u run ur script it will do nothing untill u press Spacebar, then it will run function MyFunction 1 time.
So it move mouse on given position, make pause of half second then left click on desired position $x and $y 1 time and srcipt stop untill u press space again then he make same procedure.
I added exit function so u can turn it off by just press ESC key.
HotKeySet( "{SPACE}", "MyFunction")
HotKeySet( "{ESC}", "CloseScript")
Global $x = 519 ; x is first value of mouse position
Global $y = 900 ; y is second value of mouse position
While 1
sleep(10)
Wend
Func MyFunction()
MouseMove($x, $y, 2) ; moves the mouse pointer do mouse position with speed 2
Sleep(500) ; wait 500 ms half of second ( delay )
MouseClick("left", $x, $y, 1, 2) ; now click left mouse key on mouse position, 1 click with speed 2
EndFunc
Func CloseScript()
Exit
EndFunc

Trouble binding print screen in XMonad

I'm trying to bind the print screen key in Xmonad, but it doesn't seem to work.
I have the following code in my xmonad.hs:
myKeys conf#(XConfig {XMonad.modMask = modm}) = M.fromList $
[
...
, ((0, xK_Print), spawn "scrot -q 1 $HOME/pictures/screenshots/%Y-%m-%d-%H:%M:%S.png")
...
]
However, if I press print screen nothing happens (the file isn't there). Replacing xK_Print with xK_F12 works.
Using xev, I found the keysym of print screen:
KeyPress event, serial 32, synthetic NO, window 0x1a00001,
root 0x90, subw 0x0, time 8532454, (593,435), root:(594,454),
state 0x10, keycode 218 (keysym 0xff61, Print), same_screen YES,
XKeysymToKeycode returns keycode: 107
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 32, synthetic NO, window 0x1a00001,
root 0x90, subw 0x0, time 8532501, (593,435), root:(594,454),
state 0x10, keycode 218 (keysym 0xff61, Print), same_screen YES,
XKeysymToKeycode returns keycode: 107
XLookupString gives 0 bytes:
XFilterEvent returns: False
which seems to be 0xff61. But using this instead of xK_Print doesn't work as well (I checked with ghci and xK_Print is just an alias for 0xff61).
How can I bind the print screen key to something?
Of course I can use another key for the job, but it feels silly not using print screen to take a screenshot.
Try changing the $HOME to a full, hardcoded path. I think that when xmonad.hs runs, it doesn't have access to all the environment variables.
To debug this, do the following:
Map that key to something that you know works (i.e., duplicate the key binding that you used for another, working key).
If that works, then you know that Xmonad can "see" the key.
Now map that key to what you want, but send any errors to a file. E.g.,
.... spawn "scrot -q 1 $HOME/pictures/screenshots/%Y-%m-%d-%H:%M:%S.png > /home/me/errors.log 2>&1")
See what errors you get, and deal with them.

QDialog closing crash

I have problem in ensuring the dialog is closed/released with the following Qt codes.
//Segment 1: To open a 'wait' dialog for some long-running tasks
void MainWindow::ui_showProgressDialog(QString title) {
dlgProgress = new QProgressDialog(title, tr("Cancel"), 0, 0, this);
dlgProgress->setAttribute(Qt::WA_DeleteOnClose); // line 1
dlgProgress->setModal(true);
dlgProgress->show();
connect(voidWatcher, SIGNAL(finished()),
this, SLOT(onPopulationFile()));
}
//Segment 2: Attempts to close the 'wait' dialog
void MainWindow::onPopulationFile() {
qDebug((dlgProgress == NULL) ? "true" : "false");
if (dlgProgress) //
{
qDebug("0");
dlgProgress->close(); // line 2
qDebug("1");
}
qDebug((dlgProgress == NULL) ? "true" : "false");
}
Issue: When I trigger the call 'ui_showProgressDialog' twice, the second call always crash my program. Originally, my code has no line 1 of segment 1, and from the QtCreator, it always crashes on line 2 of segment 2. Debug message shows as follow
// first call to onPopulationFile
false
0
1
false
// second call to onPopulationFile
false
0
*** CRASH ***
I read the documentation that NEVER delete objects from different threads, I'm doubt that the call 'onPopulationFile' is invoked from a non-main thread. So I added the line 1 to segment to let the program decide when the delete the object. But it seems not work. Any suggestion to the problem?
Experiment done: If I replace QProgressDialog with QDialog, the program goes without crashes, and the debug message show
// first call to onPopulationFile
false
0
1
false
// second call to onPopulationFile
false
0
1
false
So,
Why the second null test in segment 2 always fail? [Edit: I have to explicitly set the variable to NULL]
Is there any better way to close the 'wait' dialog?
I try to close/release the dialog as I want release memory as soon as possible. Do I really need to manually delete the dialog?
Platform: Qt Opensource 4.8 (x64), Windows 7 (x64), MinGW (rubenvb 4.7.2)
dlgProgress->setAttribute(Qt::WA_DeleteOnClose); deletes the widget when it is closed. As you are calling dlgProgress->close();, after this line the object it points to has been freed, and dlgProgress is now a invalid pointer.
You need to set dlgProgress to null after any call to close, or event better, use the signal Qobject::destroyed().
EDIT:
Qt::WA_DeleteOnClose specify that the object will be deleted if a close event happens. Not exactly how much time it will take. For instance if they are using QObject::deleteLater(), then the object is not deleted right away. Even if it is not the case , pieces of code like
A* a = new A;
a->dosomething();
delete a;
a->dosomething();
are undefined behavior. The second call to a->dosomething(); may crash (if you are lucky) or may not crash.

Resources