Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Hotkey toggling


  • Please log in to reply
4 replies to this topic
dblanchard
  • Members
  • 32 posts
  • Last active: Jul 16 2014 01:43 AM
  • Joined: 14 Feb 2007
[Split from Wish List. ~jaco0646]
Hotkey as Switch and Start/Stop-Toggle

Reviving this for a Mac keyboard running Windows 7

This is a great thread, and the only productive one I can find on toggling.

I have a Macbook running Win7. When I use my external keyboard, the Windows key does its job, but when I use the built-in keyboard, I want my option key to be the Windows key. I've got it mapped just the way I want it (with the exception of the fn key not being my control key), except that I want to be able to toggle my remapping using a hotkey.

Here is what works:

LWin::LAlt
RWin::RAlt
LAlt::LWin
RAlt::RControl

Here is my best attempt at what I want, using some of jonny's code (because I understand it best):

^!+z::
{
	if ((tog=="" && tog:=0) || tog ^= 1)
	{
		msgbox Toggle On
	}
	else
	{
		msgbox Toggle Off
		LWin::LAlt
		RWin::RAlt
		LAlt::LWin
		RAlt::RControl
	}
}

The attempt at using jonny's code shows the msgboxes, but shouldn't. It should show one message when I hit the key combination, but not the second message when I hit the same key combo (i.e. not moving my fingers to the new positions for control-alt-shift).

Any help?

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
Using AHK_L...
^!+z::

 toggle := !toggle

return



#if toggle

 LWin::LAlt

 RWin::RAlt

 LAlt::LWin

 RAlt::RControl

#if


Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
Using AHk_basic

I have the theory that you should be able to use this command, but I could not implement it :cry: <!-- m -->http://www.autohotke...ands/Hotkey.htm<!-- m -->

An alternate method is to use context sensitive hotkeys <!-- m -->http://www.autohotke...eys.htm#Context<!-- m -->
<!-- m -->http://www.autohotke... ... Active.htm<!-- m -->

You said that the msgbox shouldn't be there, but what about a tooltip?
The tooltip must exist for the context sensitive hotkeys to work
#singleinstance force
CoordMode, ToolTip, Screen 

x_screen_offset=1500
x_screen_offset=100

f1:: 	; <------ switching the keys confuses me so I added another hotkey
^!+z:: 
tog:=!tog
if tog
{
  tooltip, Toggle On, %x_screen_offset%, 0 
  WinGet, ID, LIST,ahk_class tooltips_class32 
  Loop, %id% 
  {  
    this_id := id%A_Index% 
    ControlGetText, tooltip2,,ahk_id %this_id% 
    ifinstring, tooltip2, Toggle On
    {
       WinSetTitle, ahk_id %this_id%, , Toggle On
       return
    }
  } 
}
else
{
  tooltip, Toggle Off, %x_screen_offset%, 0 
  sleep ,1000
  tooltip, 
}
return

#ifwinexist, Toggle On ahk_class tooltips_class32
      LWin::LAlt 
      RWin::RAlt 
      LAlt::LWin 
      RAlt::RControl 
#ifwinexist

This simpler version uses the pressence of a gui, that the use can't see but AHk can, to switch context sensitive hotkeys
The tooltip is optional
#singleinstance force
CoordMode, ToolTip, Screen 

#NoTrayIcon	; prevent the showing of a tray icon for the script 

x_screen_offset=1500
x_screen_offset=100

gui, +owner +ToolWindow

f1:: 	; <------ switching the keys confuses me so I added another hotkey
^!+z:: 
tog:=!tog
if tog
{
  tooltip, Toggle On, %x_screen_offset%, 0 
;  gui, show, NA w100 h100,Toggle On
  gui, show, NA ,Toggle On
}
else
{
  tooltip, Toggle Off, %x_screen_offset%, 0 
  gui, cancel
  sleep ,1000
  tooltip, 
}
return

#ifwinexist, Toggle On ahk_class tooltips_class32
      LWin::LAlt 
      RWin::RAlt 
      LAlt::LWin 
      RAlt::RControl 
#ifwinexist


dblanchard
  • Members
  • 32 posts
  • Last active: Jul 16 2014 01:43 AM
  • Joined: 14 Feb 2007
I won't be able to try this until I get home tonight, but I'll give it another go.

I should have explained that the msgboxes were just there so I could confirm that the toggling was happening. I don't actually want either of them.

the first solution looks like it will be just right.

Thanks to both of you for your help.

D

dblanchard
  • Members
  • 32 posts
  • Last active: Jul 16 2014 01:43 AM
  • Joined: 14 Feb 2007
jaco0646, your code works great for me, now that I have remembered your comment that I need to use Autohotkey_L.

I switched the trigger to capslock & s since using an alt key that moves as a function of the toggle was bothersome.

Thx,

D