71435

hotkeys does not work when send is in loop

Question:

Assume this code:

Loop { if enabled Send, / } m:: enabled := !enabled Return

I want to toggle sending / to a Notepad for example. But if I run this code by pressing <kbd>M</kbd> on keyboard, then pressing the M key again does not disable sending.<br /> Looks like the send command in the Loop cause this issue since Ive tried using msgbox which does not disable the m key.<br /> How can I make this code to work? (SendInput and Play does not work too)

Answer1:

It's because your loop is blocking any other execution. Unless that loop is the only thing in your script, you generally want to avoid using loops and use <a href="http://ahkscript.org/docs/commands/SetTimer.htm" rel="nofollow">timers</a> instead.

<a href="http://ahkscript.org/docs/commands/SetTimer.htm" rel="nofollow">Timers</a> don't block further execution but act more like their own thread. Here's an example using a timer:

slashTimerActive := 0 m:: if (!slashTimerActive) SetTimer, SendSlash, 100 ; Call the sub every 100ms else SetTimer, SendSlash, Off slashTimerActive := !slashTimerActive ; Flip the variable return ; Subroutine SendSlash: SendInput, / return

Recommend

  • Autohotkey, remap Left Alt + Space to Control + Escape
  • Sending a Keyboard Input with Java JNA and SendInput()
  • How to add brackets using AutoHotKey
  • Bootstrap 3 Mobile nav won collapse when you click outside it
  • add and remove classes in order with jQuery
  • iphone how to send my project build to someone else
  • Limit on amount of rows retrieved MySql, Laravel
  • EditText is covered by Keyboard
  • Motorola barcode scanner SDK events C#
  • What is the difference between a “service account” and an “installed application”?
  • jQuery: How to AJAXify WordPress Search?
  • Android device acting as an accessory
  • Clear fused location provider's location for testing
  • Sending keystrokes/mouse clicks to a Java program with Autohotkey
  • Limiting recursion to certain level - Duplicate rows
  • Why value captured by reference in lambda is broken? [duplicate]
  • Display issues when we change from one jquery mobile page to another in firefox
  • Jenkins: How To Build multiple projects from a TFS repository?
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Different response to non-authenticated users and AJAX calls
  • jQuery show() function is not executed in Safari if submit handler returns true
  • How do I fake an specific browser client when using Java's Net library?
  • Updating server-side rendering client-side
  • javascript inside java/jsp code
  • WinForms: two way TextBox problem
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Adding custom controls to a full screen movie
  • Apache 2.4 - remove | delete | uninstall
  • R: gsub and capture
  • How to pass list parameters for each object using Spring MVC?
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Data Validation Drop Down Box Arrow Disappearing
  • Comma separated Values
  • How to disable jQuery.jplayer autoplay?
  • Why joiner is not used after Sequence generator or Update statergy
  • sending mail using smtp is too slow
  • Recursive/Hierarchical Query Using Postgres
  • UserPrincipal.Current returns apppool on IIS
  • How to load view controller without button in storyboard?