Using auto hotkey to swap Ctrl & Alt and implement Ctrl Tab - keyboard-shortcuts

While using AutoHotKey I wanted to setup a rule to swap the left alt and left ctrl. I can do this by doing:
LAlt::LCtrl
LCtrl::LAlt
I then wanted to keep the 'alt tab' functionality bound do those physical keys, thus I tried
LCtrl & Tab::AltTab
In addition to the two uptop, yet it won't work. If I put it like so:
LCtrl & Tab::AltTab
LAlt::LCtrl
LCtrl::LAlt
Then the tab will work, however the ctrl alt swap will be broke. Any suggestions?

The hotkey documentation talks about wildcards
Wildcard: Fire the hotkey even if extra modifiers are being held down. This is often used in conjunction with remapping keys or buttons. For example:
*#c::Run Calc.exe ; Win+C, Shift+Win+C, Ctrl+Win+C, etc. will all trigger this hotkey.
*ScrollLock::Run Notepad ; Pressing Scrolllock will trigger this hotkey even when modifer key(s) are down.
So try this
*tab::
{ if(GetKeyState("LAlt", "P"))
{ Send {LControl up}{Alt down}{tab}
KeyWait, tab
}else
{ send {tab}
}
return
}
~LAlt Up::
{ send {lalt up}
return
}
LAlt::LCtrl
LCtrl::LAlt

I improved this slightly to fix shift tab not working, now you can use Shift+tab as expected where as before you couldn't (was frustrating trying to fix indentation(outdent) when coding) I may improve this more and get Shift+Alt+Tab working
*tab::
{
if(GetKeyState("LAlt", "P")){
Send {LControl up}{Alt down}{tab}
KeyWait, tab
} else if(GetKeyState("LShift", "P")){
Send {LShift down}{tab}
KeyWait, tab
}else
{ send {tab}
}
return
}
~LAlt Up::
{ send {lalt up}
return
}
LAlt::LCtrl
LCtrl::LAlt

Just ran into the same problem myself, was looking for a more straightforward solution. If you swap Alt and Ctrl using SharpKeys (or other registry remapping tool) from there it's a simple:
RCtrl & Tab::AltTab

Related

Jetpack Compose - ModalBottomSheet comes up with soft keyboard

I have a problem with ModalBottomSheet and it's on my work computer so I can't record it to you right now. So basically, after I give focus to one of my TextFields, my keyboard comes up and pushes all the content upwards so I can see the TextField that I'm writing to. When I'm hiding my keyboard I can see that my ModalBottomSheet hides too, but I never set it to come up.
So if you are familiar with this bug, please let me know your solutions.
My coworker, so he inserted a boolean that checks if keyboard is up or not and if it is, dont put ap modal bottom sheet.
You can use this method until this problem is fixed with an additional update.
You can use LaunchedEffect for this. Here is an example for you.
The important thing here is to disable the ModalBottomSheetDialog when the keyboard is opened and re-enable it half a second after the keyboard is closed.
You can trigger the required function by assigning a value to this variable when the keyboard is turned on, and then changing and checking this value when the keyboard is closed.
/*Change this value to "keyboard_on" when the keyboard is turned on and "keyboard_off" when the keyboard is closed again. You can give different names for different usage areas. That's why we're using a string, not a Boolean.*/
var taskCodeValue = remember { mutableStateOf("keyboard_off") }
var sheetOpener by remember { mutableStateOf(true) }
if (taskCodeValue.value == "keyboard_off"){
LaunchedEffect(taskCodeValue.value == "keyboard_off"){
delay(500)
sheetOpener = true
}
}else {
sheetOpener = false
}
/*
By adding the Scaffold, which includes ModalBottomSheet and other compose
elements, into a box, we enable them to work independently of each other.
*/
Box(modifier = Modifier.fillMaxSize()) {
Scaffold(
content = {}
)
if (sheetOpener){
ModalBottomSheetLayout(
sheetState = sheetState,
sheetContent = {}
) {}
}
}

Auto Clicker for AHK that clicks and holds down control, only while i press F9

I need a script in AHK that auto-clicks and holds down the control key at the same time for a software that I am using. I would love to be able to bind that action to like F9
I have found scripts that auto click, but they are toggles and I don't know how to add the function of holding down control at the same time.
This is a bit more compact. Note that this is also setup for using ctrl+F9 because once control is held down, F9 won't turn off the autoclicking since it thinks you're pressing ctrl+F9. It will click wherever your mouse is, but you can add coordinates if you want to click in a specific location. I put a sleep in there for 50ms, but modify to suit your needs.
f9::
^f9::
Send , % ( bT := !bT ) ? "{ctrl down}" : ""
While( bT )
{
Click ; Clicks wherever your mouse is. Add coordinates if you need a specific pos.
Sleep , 50
}
Send , {ctrl up}
Return
q::
auto = true
send, {CONTROL DOWN}
while(auto){
mouseclick, left, "X-Cord","Y-Cord"
if GetKeyState(q)
auto =true
}
send, {CONTROL UP}
return
As you cant run 2 commands at the literal same time this should work.
If you wanted to be more precise depending on what your using it for,
this would be better:
q::
x := ;place your desired coordinates in these two variables.
y :=
f1::
{
mousegetpos, start_x, start_y
auto = true
send, {CONTROL DOWN}
while(auto){
mouseclick, left, %x%, %y%, 1, 0
if GetKeyState(q)
auto =true
}
send, {CONTROL UP}
mousemove, %start_x%, %start_y%, 0
}
return
This will get your cursor position, move cursor to point as fast as possible, hold control down, left click, let go of control, return to original position.
Use 'q' to start and terminate

AutoHotkey - Perform action based on clicked menu item

I looked around the AHK forums, google, and here on stack overflow and could not find any method for pulling this off, so thanks BIG TIME in advance if you can figure this one out. I am using notepad in my examples, but I'm writing this script for a complicated Point Of Sale program.
I want to do something almost exactly like this, but using the application menus as described below instead of a button.
I would like to have a script that performs an action if a certain menu item is clicked. It does not matter whether that is determined by menu position, label or otherwise. Cursor position, however, is probably not viable for my needs.
A simple example of this would be to open a MsgBox when File-Open is selected with the mouse in notepad.
I have implemented a few techniques that enabled me to pull variables out of most control objects following a left click (buttons, drop-down menus, etc), but when I use the application menu (for example, in notepad: file-save or file-open) It returns a blank string. For example:
#z::
MouseGetPos,,,,Ctrl,2
ControlGetText, Text,,ahk_id %Ctrl%
MouseClick, left
Sleep 2500
MsgBox, %Text%
(Note that I used windows-z so as to not return a MsgBox after every left-click.)
Will return 'cancel' if the cancel button was pressed in the 'file-save as' dialogue of notepad, but returns nothing if I activate it while selecting anything from the application menus (file, edit, format, etc.)
I know that these menus are accessible to AHK, as you can do the following do activate 'File-Save' from the notepad menu:
WinMenuSelectItem, Untitled - Notepad,File,Save
But when I use window spy, I see the objects behind the menu, rather than strings that are actually in the menu.
Are these menus actually separate windows that I need to switch to active to read? Or am I trying to do something impossible?
Big thanks in advance, this is something that's been driving me crazy!
Menus are not that easy to get info from, at least not with autohotkeys built-in commands, you will need to use DllCall's to get the info you need.
I have made you an example that works with notepad for me on win7 64b
What i did in the example is look for notepad run it if its not there then get the ID (hWnd) of the notepad window
When you press ctrl + LButton a DllCall to GetMenu using the ID of the notepad window is used to get a menu handle.
After that more DllCall's are used to get things like GetMenuItemCount, GetSubMenu and GetMenuItemInfo.
What this does is it lets us loop over the menu items one by one and getting info about them, in this example we're getting the state of the items, specifically the highlight state.
When an item is found that has the highlight state the script stores the indexs of the item and breaks the loops.
As this is only an example all it does is display a string message with the index numbers and sends a LButton press
Example:
ifWinNotExist, ahk_class Notepad
{
Run, notepad.exe
WinWait, ahk_class Notepad
}
WinGet, hWnd, ID,
^Lbutton::
hMenu :=DllCall("GetMenu", "Uint", hWnd)
loop % (count := DllCall("GetMenuItemCount", "ptr", hMenu))
{
menu_index := A_index
; Note that menu item positions are zero-based.
hSubMenu := DllCall("GetSubMenu", "Uint", hMenu, "int", (A_index-1))
; Set the capacity of mii to sizeof(MENUITEMINFO)
VarSetCapacity(mii, A_PtrSize=8 ? (Size:=80) : (Size:=48), 0)
; Set the cbSize field to sizeof(MENUITEMINFO)
NumPut(Size, mii, 0)
; Set the mask to whatever you want to retrieve.
; In this case I set it to MIIM_STATE=1.
NumPut(1, mii, 4)
loop % (subCount := DllCall("GetMenuItemCount", "ptr", hSubMenu))
{
Sub_index := A_index
; Note that menu item positions are zero-based.
DllCall("GetMenuItemInfo", "UInt", hSubMenu, "UInt", (A_index-1), "UInt", 1, "UInt", &mii)
; Get the state field out of the struct.
fState := NumGet(mii, 12)
if (fState & 0x80) ; 0x80 MFS_HILITE | 0x8 MFS_CHECKED
{
MenuString := "Found in top #" menu_index " Sub pos #" Sub_index
break 2
}
}
}
if (MenuString)
{
Tooltip % MenuString
}
else
{
tooltip no menu item highlighted
}
send {Lbutton}
return
I hope that helps you get an idea of what is needed to do what your trying to do, other possible DllCalls to Look at are MenuItemFromPoint, GetMenuString.
This can take time to get right, but with the Dllcalls i have shown in this example, I hope that you can find other examples of how to use them with autohotkey on the forums.
This AutoHotkey script should do what you require.
It has been tested on Notepad (Windows 7), and should be readily adaptable to other programs that use the standard context menus still used in the vast majority of software. Although many programs use custom menu bars, the context menus are often still standard context menus.
I have provided two scripts, one will show a ToolTip and block triggering a menu item, whenever any menu item is pressed, which is useful for understanding and for diagnostic purposes.
The second script will show a ToolTip and block triggering any menu item if its text string starts with 'Open'.
Note: the text of the Notepad menu item is
Open... Ctrl+O (Open...[tab]Ctrl+O) and not simply 'Open'.
-
;==================================================
;tested on Notepad (Windows 7)
;block any clicks on any menu items when notepad is the active window
;note: to bypass this and click an item anyway, use ctrl+click
;note: requires Acc.ahk library in AutoHotkey\Lib folder
;https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk
;on right of screen right-click Raw, Save target as...
#IfWinActive, ahk_class Notepad
;LButton::
CoordMode, Mouse, Screen
MouseGetPos, , , hWnd
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass in #32768
{
vCount++ ;your code here
ToolTip blocked %vCount%, 500, 200 ;your code here
Return
}
SendInput {LButton Down}
KeyWait, LButton
MouseGetPos, vPosX, vPosY, hWnd
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass in #32768
{
ControlSend, Dummy, {Click, 0, 0}, ahk_class Notepad
vCount++ ;your code here
ToolTip blocked %vCount%, 500, 200 ;your code here
Return
}
SendInput {LButton Up}
Return
#IfWinActive
;==================================================
;tested on Notepad (Windows 7)
;block any clicks on the 'open' menu item when notepad is the active window
;note: to bypass this and click an item anyway, use ctrl+click
;note: requires Acc.ahk library in AutoHotkey\Lib folder
;https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk
;on right of screen right-click Raw, Save target as...
#IfWinActive, ahk_class Notepad
LButton::
CoordMode, Mouse, Screen
MouseGetPos, , , hWnd
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass in #32768
{
vItemText := ""
oAcc := Acc_Get("Object", "1", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (oAcc.accState(A_Index) & 0x80) ;MF_HILITE := 0x80
if (1, vItemText := oAcc.accName(A_Index))
break
if (SubStr(vItemText, 1, 4) = "Open")
{
vCount++ ;your code here
ToolTip blocked %vCount%, 500, 200 ;your code here
Return
}
}
SendInput {LButton Down}
KeyWait, LButton
MouseGetPos, vPosX, vPosY, hWnd
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass in #32768
{
ControlSend, Dummy, {Click, 0, 0}, ahk_class Notepad
vItemText := ""
oAcc := Acc_Get("Object", "1", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (oAcc.accState(A_Index) & 0x80) ;MF_HILITE := 0x80
if (1, vItemText := oAcc.accName(A_Index))
break
if (SubStr(vItemText, 1, 4) = "Open")
{
vCount++ ;your code here
ToolTip blocked %vCount%, 500, 200 ;your code here
Return
}
}
SendInput {LButton Up}
Return
#IfWinActive
;==================================================
Note:
The code samples posted in the two links below, achieve related goals.
Is it possible to catch the close button and minimize the window instead? AutoHotKey
AutoHotKey: Run code on Window Event (Close)
Note:
The function JEE_MenuIsActive, link below, can be used to check whether
the menu bar/sysmenu bar is active
in order to distinguish title bar menus from right-click context menus.
GUI COMMANDS: COMPLETE RETHINK - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=25893

How to prevent window from loosing focus when receiving a grabbed key from X11

My window calls hide() when a QEvent::FocusOut is received. Simultaniously I want its visibility to be toggled if a hotkey is pressed. Now I have the following problem: Pressing the hotkey, registered with XGrabKex(...) seems to steel the focus of my app. Resulting in an unwanted behaviour. If my app is visible the hotkeyevent steels focus, which results in a QEvent::FocusOut, which hides my app, and after that the hotkey is received which toggles visibility (shows) my app. I.e. my app does not hide when pressing the hotkey.
Is there a way to tell the x window system to not steel the focus when a grabbed key is pressed? Or are there other possible solutions to this problem?
A couple of different methods.
Use XQueryKeymap to see which keys are pressed. For instance, when you get a FocusOut event, call XQueryKeymap and see if your hotkey is pressed. If it is not, hide the window; if it is, don't hide it and wait for the hotkey event.
Delay hiding on FocusOut by 100 or so milliseconds. Cancel hiding if you either get the hot key or get your focus back during this time interval.
Look also here for useful info.
Finally got it to work in a "proper" way:
bool MainWidget::nativeEvent(const QByteArray &eventType, void *message, long *)
{
#ifdef Q_OS_LINUX
if (eventType == "xcb_generic_event_t")
{
xcb_generic_event_t* event = static_cast<xcb_generic_event_t *>(message);
switch (event->response_type & 127)
{
case XCB_FOCUS_OUT: {
xcb_focus_out_event_t *fe = (xcb_focus_out_event_t *)event;
if ((fe->mode==XCB_NOTIFY_MODE_GRAB && fe->detail==XCB_NOTIFY_DETAIL_NONLINEAR)
|| (fe->mode==XCB_NOTIFY_MODE_NORMAL && fe->detail==XCB_NOTIFY_DETAIL_NONLINEAR ))
hide();
break;
}
}
}
#endif
return false;
}

Tool Tip obscures button

I want to pop up a tool tip when mouse moves over button, to explain what will happen if the user clicks on the button.
This code seems to do the job ( except for a big snag )
wxHelpProvider::Set(new wxSimpleHelpProvider);
...
btnDisplay = new wxButton( this, -1,
"DISPLAY", wxPoint(10,35));
btnDisplay->SetHelpText("Click to display this dimension");
btnDisplay->Bind( wxEVT_ENTER_WINDOW, &cHiddenDimensionPanel::OnDisplayHelp, this );
...
void cHiddenDimensionPanel::OnDisplayHelp(wxMouseEvent& event)
{
wxHelpProvider::Get()->ShowHelp((wxWindowBase*)event.GetEventObject());
}
The snag is that the tooltip obscures the button! If I click on it, the tool tip vanishes for a moment, but immediately pops back up. It is not possible to click the button under the tooltip.
You should be using the SetToolTip(const wxString &tipString) method, and letting wx handle showing/hiding the tooltip - not re-appropriating the HelpText property and manually managing the tooltip display.