libreadline is not exiting on Ctrl+C from paginated "__more__" output state (possible completions on tab) - sigint

My application uses libreadline to auto complete timezone strings (on pressing tab) for timezone command.
As there are lot of possible completions the output is paginated with __more__.
In this state if I press q it exits fine but if I press Ctrl+C the behavior is as shown below.. (it wont exit until all the entries in the buffer printed out, but printing junk).
$ timezone <tab>
Display all 200 possibilities? (y or n) y
Africa/Maputo America/Moncton Asia/Kuwait Europe/Stockholm
Africa/Maseru America/Monterrey Asia/Macau Europe/Tallinn
Africa/Mbabane America/Montevideo Asia/Magadan Europe/Tirane
Africa/Mogadishu America/Montreal Asia/Makassar Europe/Uzhgorod
Africa/Monrovia America/Montserrat Asia/Manila Europe/Vaduz
--More--^C
�"^TxU ^P�"^TxU ��"^TxU ��"^TxU
^P^?"^TxU ^P�"^TxU ��"^TxU ��"^TxU
0�"^TxU ^P�"^TxU ��"^TxU ��"^TxU
0�"^TxU ^P�"^TxU ��"^TxU ��"^TxU
0�"^TxU ^P�"^TxU ��"^TxU ��"^TxU
0�"^TxU ��"^TxU ��"^TxU ^P�"^TxU
0�"^TxU ��"^TxU ��"^TxU #�"^TxU
By the way my SIGINT handler function is as below, and I am using rl_attempted_completion_function to register my own function to provide possible completion strings char**.
rl_initialize();
printf("\n");
rl_forced_update_display();
How to make Ctrl+C to behave exactly as pressing q on pagination?.

Related

How to toggle an AHK script on/off with a key?

I'm working on a Script that constrains the movement of the cursor to the horizontal direction only. I would like to activate and deactivate it using the same hotkey.
I'm using this code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
!s:: ; Hotkey will toggle status
Confine := !Confine
MouseGetPos, , SetY
ClipCursor( Confine, 0, SetY, A_ScreenWidth, SetY+1 )
return
!a::
Pause
Suspend
return
ClipCursor( Confine=True, x1=0 , y1=0, x2=1, y2=1 ) {
VarSetCapacity(R,16,0), NumPut(x1,&R+0),NumPut(y1,&R+4),NumPut(x2,&R+8),NumPut(y2,&R+12)
Return Confine ? DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" )
}
The code works, but when pressing ctrl + a the script doesn't stop.
Am I using incorrectly the pause and suspend commands? How could this task be done?
That's a neat function! I can definitely see some use for that. Anyway, you are correctly using Pause and Suspend, but it appears that !s was meant to toggle it on and off (so, no need for !a).
For some reason, though, it won't toggle off. In my testing, the function was correctly seeing the value of "Confine", but wasn't returning the false-portion of the ternary operation. It appears to be coded properly, but I suspect there may be an issue (possible bug?) with Return evaluating "Confine" properly.
Here are a few solutions:
By testing explicitly whether "Confine" is equal to True works.
Return ( Confine = True ) ? DllCall( "ClipCursor" , UInt , &R ) : DllCall( "ClipCursor" )
What I would do, however, is take the ternary operation out of the function and move it to your hotkey to avoid needless operations and assignments if it evaluates to false. To me, this is a bit cleaner.
!s:: ; Hotkey will toggle status
Confine := !Confine
MouseGetPos ,, SetY
Confine ? ClipCursor( 0 , SetY , A_ScreenWidth , SetY+1 ) : DllCall( "ClipCursor" )
Return
ClipCursor( x1=0 , y1=0 , x2=1 , y2=1 ) {
VarSetCapacity( R , 16 , 0 )
NumPut( x1 , &R + 0 )
NumPut( y1 , &R +4 )
NumPut( x2 , &R +8 )
NumPut( y2 , &R +12 )
Return DllCall( "ClipCursor" , UInt , &R )
}
If you just want to use !a to turn it off, you could just do this, !a::DllCall( "ClipCursor" ). If you decide to go this route, I would recommend removing all of the toggle portions of code from the hotkey and function.

Can't run DrRacket or gracket 7.0

When I open DrRacket.app v7.0 on OSX 10.7.5, I get this error message:
LSOpenURLsWithRole() failed with error -10810 for the file /Applications/Racket v7.0/DrRacket.app.
Running drracket from the command line yields some more detail:
ffi-lib: couldn't open "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics.dylib" (dlopen(/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics.dylib, 6): image not found)
context...:
"/Applications/Racket v7.0/share/pkgs/gui-lib/mred/private/wx/cocoa/utils.rkt": [running body]
for-loop
run-module-instance!125
for-loop
[repeats 1 more time]
run-module-instance!125
for-loop
[repeats 1 more time]
run-module-instance!125
for-loop
[repeats 1 more time]
run-module-instance!125
do-dynamic-require5
"/Applications/Racket v7.0/share/pkgs/gui-lib/mred/private/wx/platform.rkt": [running body]
for-loop
run-module-instance!125
...
Any suggestions for what I should try?
I figure that the problem is most likely that I'm running an old version of OSX. CoreGraphics was introduced in 10.8. I've looked for documentation on what OS versions each version of Racket requires, and haven't yet found anything. Does anyone know where it is?
Matthew Flatt kindly answered my question on the Racket github. DrRacket and gracket in Racket 7.0 will indeed run on OSXes earlier than 10.8. To get them to work:
Change line 41 of share/pkgs/gui-lib/mred/private/wx/cocoa/utils.rkt to:
(define cg-lib (ffi-lib (format "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics") #:fail (lambda () #f)))
In share/pkgs/gui-lib/mred/private/wx/cocoa/queue.rkt, change this line:
(define-cg CGEventTapCreate (_fun _uint32 _uint32 _uint32 _uint64
(_fun #:atomic? #t
#:keep mb-detect-box
_pointer _uint32 _id _pointer -> _id)
_pointer
-> _pointer))
to:
(define-cg CGEventTapCreate (_fun _uint32 _uint32 _uint32 _uint64
(_fun #:atomic? #t
#:keep mb-detect-box
_pointer _uint32 _id _pointer -> _id)
_pointer
-> _pointer) #:fail (lambda () #f))
and this line:
(define-cg CGEventGetLocation (_fun _pointer -> _NSPoint))
to:
(define-cg CGEventGetLocation (_fun _pointer -> _NSPoint) #:fail (lambda () #f))
These changes remove the dependency on CoreGraphics.

Resizing Google Hangouts app on Win 10 with Autohotkey

I need to resize Google Hangouts app in Win 10. through Autohotkey
Currently it is 260*460, and I need it to be 1150*750.
Here are the Window spy data:
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Hangouts
ahk_class Chrome_WidgetWin_1
>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen: 901, 600 (less often used)
In Active Window: -759, 580
>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
Color: 0xF0F0F0 (Blue=F0 Green=F0 Red=F0)
>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: 1660 top: 20 width: 260 height: 460
>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<
>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
Chrome Legacy Window
>>>>>>>>>>>( Hidden Window Text )<<<<<<<<<<<
>>>>( TitleMatchMode=slow Visible Text )<<<<
>>>>( TitleMatchMode=slow Hidden Text )<<<<
I tried something like the following, but it didn't work:
[code]
#Persistent
Loop
{
WinWaitActive, ahk_class Chrome_WidgetWin_1
WinMove, ahk_class Chrome_WidgetWin_1, , 1150, 750
}
Return
[/code]
The WinMove command requires those arguments:
WinMove, WinTitle, WinText, X, Y [, Width, Height, ExcludeTitle, ExcludeText]
The arguments WinText, X and Y can be ommited in which case you leave them empty, but you still have to use the commas to indicate them.
You only left the argument WinText empty and the arguments with value 1150 and 750 got interpreted as arguments X and Y.
The solution is to add those two unused arguments X and Y:
WinMove, ahk_class Chrome_WidgetWin_1, , , , 1150, 750
If for example you want to also move the window to the positions 200, 100, then use the X and Y arguments as well:
WinMove, ahk_class Chrome_WidgetWin_1, , 200, 100, 1150, 750
; WinMove, WinTitle (or) ahk_class WinClass, WinText, X, Y , Width, Height, ExcludeTitle, ExcludeText
WinMove, ahk_class Chrome_WidgetWin_1, , , , 1150, 750

autohotkey caps lock to ctrl not releasing

I'm using AutoHotkey to map the Caps Lock to Ctrl, and trying to use the Ctrl + K as Tab in Total Commander.
SetCapsLockState AlwaysOff
Capslock::Ctrl
#ifWinActive ahk_class TTOTAL_CMD
^k::Send, {Tab}
#ifWinActive
When i using the Ctrl + K remap with the normal Ctrl, it works fine. But when i trying to use it with the Caps Lock + K, then it works for the first time, but while i'm not releasing the Caps Lock, it sends k instead of Tab. The log says:
008: SetCapslockState,AlwaysOff
009: Return (3.49)
; Hiting Ctrl + K twice.
081: Send,{Tab} (0.02)
081: Return (0.30)
081: Send,{Tab} (0.02)
081: Return (1.59)
; Hiting Caps Lock + K twice.
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.47)
081: Send,{Tab} (0.01)
081: Return (0.73)
; The second Tab is missing, a simple K sent.
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (3.06)
Here is the log, when i pressing Caps Lock + K, releasing it, then pressing againg:
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.34)
081: Send,{Tab} (0.01)
081: Return (0.08)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (0.34)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.19)
081: Send,{Tab} (0.01)
081: Return (0.06)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (3.00)
I think the source of the problem may be in the CapsLock::Ctrl, but i didn't find any solution for it. Somebody meet with this problem?
EDIT:
Another interesting thing is when i sending code instead of a simple key, it works without releasing the caps lock:
^e::PostMessage, 1075, 3005, , , ahk_class TTOTAL_CMD ; cm_SwitchToNextTab=3005;Switch to next Tab (as Ctrl+Tab) (see TOTALCMD.INC file)
The log says:
008: SetCapslockState,AlwaysOff
009: Return (8.88)
; Ctrl + E twice.
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (0.36)
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (1.76)
009: SetKeyDelay,-1
; Caps Lock + E twice.
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.34)
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (0.39)
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (0.28)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (1.47)
; Caps Lock + E twice with releasing.
008: SetCapslockState,AlwaysOff
009: Return (2.54)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.34)
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (0.09)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (0.25)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.23)
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (0.08)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (1.98)
I remember running into odd issues like this when I was doing CapsLock remaps as well. Instead of mapping CapsLock to control and then using that combination in your hotkey, you could set CapsLock to do nothing but check the key's state in the #If directive. I would think this would resolve most of those odd issues.
SetCapsLockState, AlwaysOff
CapsLock::Return
#If WinActive("ahk_class TTOTAL_CMD") and GetKeyState("CapsLock", "P")
k::Send, {Tab}
I personally would just check if your window is active on ^k keypress and go from there. I used Untitled - Notepad so I could test.
CapsLock::Ctrl
^k::
{
IfWinActive, Untitled - Notepad
SendInput, {tab}
else
Msgbox
return
}

PostMessage goes wrong if I press CTRL or SHIFT

HoldLeftClick(600, 400, 4000, WindowName) ; ( coord x, coord y, delay in ms, window name where to hold left click)
HoldLeftClick(x, y, delay, Window) {
PostMessage, 0x201, , ((y<<16)^x), , %Window% ;WM_LBUTTONDOWN
sleep, delay
PostMessage, 0x202, , ((y<<16)^x), , %Window% ;WM_LBUTTONUP
}
I have this code and I am using it to hold left click on a specified window.
My problem is that if I press CTRL key or SHIFT key, bad things happens in that window, same thing happens if the window is in background and I have other window that is active!
Is there a way to prevent this?