Just a suggestion. Do all of the following:
Step 1. Remove the
return that appears immediately before the gosub routine
_SendU_Remove_Tooltip.
Step 2. Move the gosub routine
_SendU_Remove_Tooltip from its position near the end of the file to
inside the function
_SendU_Dynamic_Mode_Tooltip, at the very end of the function, with a
return immediately preceding it.
Step 3. In the same way, move the gosub routine
_SendU_restore_Clipboard from its position near the end of the file to
inside the function
_SendU__SendU_Clipboard_Mode_Tooltip, at the very end of the function, with a
return immediately preceding it.
Step 4. Comment out or delete the gosub routines
_SendU_Try_Dynamic_Mode (which is co-labeled with
_SendU_Change_Dynamic_Mode) and
_SendU_Toggle_Clipboard_Restore_Mode, because they don't appear to be used at all. If they're meant to be used by a script that includes SendU, turn them into functions.
If you do this, the module can be #included anywhere within another script without fear that the return mentioned in Step 1 will cause non-execution of any code that follows the #include. This happened to me when I included SendU near the top of a script I wrote, so I made the above changes and everything works fine.
When you're done, the script should look like this (and if you delete the gosub routines at the end instead of commenting them out, the "LABELS AND INCLUDES" comment will be unnecessary):
Code:
/*
------------------------------------------------------------------------
SendU module for sending Unicode characters
http://www.autohotkey.com
------------------------------------------------------------------------
Version: 0.0.9 2008-01-22 public beta
License: GNU General Public License
Author: FARKAS Máté <http://fmate14.try.hu> (My given name is Máté)
Tested Platform: Windows XP/Vista
Tested AutoHotkey Version: 1.0.47.04
Lastest version: http://autohotkey.try.hu/SendU/SendU.ahk
Contributors:
* Laszlo Hars <www.Hars.US>
original SendU function, _SendU_UnicodeChar function
and some bugfixes
* Shimanov
original SendU function
------------------------------------------------------------------------
If you would like help to me...
Please correct my english misspellings...
------------------------------------------------------------------------
TODO: save/load dynamic modes to/from file
TODO: detect best modes for processes (programs). I need help.
------------------------------------------------------------------------
*/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; PUBLIC GLOBAL VARIABLES FOR LOCALIZE
; See the _SendU_Load_Locale() function!
; PRIVATE GLOBAL VARIABLES
; _SendU_*** : unicode number -> utf8 character
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; PUBLIC FUNCTIONS
SendCh( Ch ) ; Character number code, for example 97 (or 0x61) for 'a'
{
Ch += 0
if ( Ch < 0 ) {
; What do you want???
return
} else if ( Ch < 33 ) {
; http://en.wikipedia.org/wiki/Control_character#How_control_characters_map_to_keyboards
Char = ;
if ( Ch == 32 ) {
Char = {Space}
} else if ( Ch == 9 ) {
Char = {Tab}
} else if ( Ch > 0 && Ch <= 26 ) {
Char := "^" . Chr( Ch + 64 )
} else if ( Ch == 27 ) {
Char = ^{VKDB}
} else if ( Ch == 28 ) {
Char = ^{VKDC}
} else if ( Ch == 29 ) {
Char = ^{VKDD}
} else {
SendU( Ch )
return
}
Send %Char%
} else if ( Ch < 129 ) {
; ASCII characters
Char := "{" . Chr( Ch ) . "}"
Send %Char%
} else {
; Unicode characters
SendU( Ch )
}
}
SendU( UC )
{
UC += 0
if ( UC <= 0 )
return
mode := SendU_Mode()
if ( mode = "d" ) { ; dymamic
WinGet, pn, ProcessName, A
mode := _SendU_Dynamic_Mode( pn )
}
if ( mode = "i" ) ; input
_SendU_Input(UC)
else if ( mode = "c" ) ; clipboard
_SendU_Clipboard(UC)
else if ( mode = "a" ) { ; {ASC nnnn}
if ( UC < 256 )
UC := "0" . UC
Send {ASC %UC%}
} else {
_SendU_Input(UC)
; If dynamic mode is bad...
; SendU_Mode("d")
; SendU( UC )
}
}
SendU_Mode( newMode = -1 )
{
static mode := "i"
if ( newmode == "d" || newMode == "i" || newmode == "a" || newmode == "c" )
mode := newMode
return mode
}
SendU_Clipboard_Restore_Mode( newMode = -1 )
{
static mode := 1
if ( newMode == 1 || newMode == 0 ) ; Enable, disable
mode := newMode
else if ( newMode == 2 ) ; Toggle
mode := 1 - mode
return mode
}
SendU_Try_Dynamic_Mode()
{
WinGet, processName, ProcessName, A
mode := _SendU_GetMode( processName )
if ( mode == "i" )
mode = a
else if ( mode == "a" )
mode = c
else
mode = i
_SendU_Dynamic_Mode_Tooltip( processName, mode )
_SendU_SetMode( processName, mode )
_SendU_Dynamic_Mode( "", 1 ) ; Clears the PrevProcess variable
}
SendU_Init( mode = "d" )
{
SendU_Mode( mode )
_SendU_Load_Locale()
_SendU_Load_Dynamic_Modes()
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; PRIVATE FUNCTIONS
_SendU_Input( UC )
{
; Original SendU function written by Shimanov and Laszlo
; http://www.autohotkey.com/forum/topic7328.html
static buffer := "#"
if buffer = #
{
VarSetCapacity( buffer, 56, 0 )
DllCall("RtlFillMemory", "uint",&buffer,"uint",1, "uint", 1)
DllCall("RtlFillMemory", "uint",&buffer+28, "uint",1, "uint", 1)
}
DllCall("ntdll.dll\RtlFillMemoryUlong","uint",&buffer+6, "uint",4,"uint",0x40000|UC) ;KEYEVENTF_UNICODE
DllCall("ntdll.dll\RtlFillMemoryUlong","uint",&buffer+34,"uint",4,"uint",0x60000|UC) ;KEYEVENTF_KEYUP|
Menu, Tray, Icon,,, 1 ; Freeze the icon
Suspend On ; SendInput conflicts with scan codes (SC)!
DllCall("SendInput", UInt,2, UInt,&buffer, Int,28)
Suspend Off
Menu, Tray, Icon,,, 0 ; Unfreeze the icon
return
}
_SendU_Clipboard( UC )
{
Critical
restoreMode := SendU_Clipboard_Restore_Mode()
utf := _SendU_GetVar(UC)
if not utf
{
utf := _SendU_UnicodeChar(UC)
_SendU_SetVar(UC, utf)
}
if restoreMode
_SendU_SaveClipboard()
Transform Clipboard, Unicode, %utf%
ClipWait
SendInput ^v
Sleep, 50 ; see http://www.autohotkey.com/forum/viewtopic.php?p=159301#159306
if restoreMode {
_SendU_Last_Char_In_Clipboard( Clipboard )
SetTimer, _SendU_restore_Clipboard, -3000
}
Critical, Off
return
_SendU_Restore_Clipboard:
Critical
if ( _SendU_Last_Char_In_Clipboard() == Clipboard )
_SendU_RestoreClipboard()
_SendU_Last_Char_In_Clipboard( "" )
Critical, Off
return
}
; --------------------- functions for clipboard mode ----------------------------
_SendU_RestoreClipboard()
{
_SendU_SaveClipboard(1)
}
_SendU_SaveClipboard( restore = 0 )
{
static cb
if ( !restore && _SendU_Last_Char_In_Clipboard() == "" )
cb := ClipboardALL
else
Clipboard := cb
}
_SendU_Last_Char_In_Clipboard( newChar = -1 )
{
static ch := ""
if ( newChar <> -1 )
ch := newChar
return ch
}
_SendU_UnicodeChar( UC ) ; Return the Utf-8 char from the Unicode numeric code (UC)
{ ; Written by Laszlo Hars
VarSetCapacity(UText, 4, 0)
NumPut(UC, UText, 0, "UShort")
VarSetCapacity(AText, 4, 0)
DllCall("WideCharToMultiByte"
, "UInt", 65001 ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
, "UInt", 0 ; dwFlags
, "Str", UText ; LPCWSTR lpWideCharStr
, "Int", -1 ; cchWideChar: size in WCHAR values: Len or -1 (= null terminated)
, "Str", AText ; LPSTR lpMultiByteStr
, "Int", 4 ; cbMultiByte: Len or 0 (= get required size / allocate!)
, "UInt", 0 ; LPCSTR lpDefaultChar
, "UInt", 0) ; LPBOOL lpUsedDefaultChar
return %AText%
}
_SendU_Get_Mode_Name( mode )
{
if ( mode == "c" && SendU_Clipboard_Restore_Mode() )
mode = r
m := _SendU_GetVar( "Mode_Name_" . mode )
if ( m == "" )
m := _SendU_GetVar( "Mode_Name_0" )
return m
}
_SendU_Get_Mode_Type( mode )
{
if ( mode == "c" && SendU_Clipboard_Restore_Mode() )
mode = r
m := _SendU_GetVar( "Mode_Type_" . mode )
if ( m == "" )
m := _SendU_GetVar( "Mode_Type_0" )
return m
}
_SendU_Dynamic_Mode_Tooltip( processName = -1, mode = -1 )
{
tt := _SendU_getVar("DYNAMIC_MODE_TOOLTIP")
if not tt
return
if ( processName = -1 || mode == -1 ) {
WinGet, processName, ProcessName, A
mode := _SendU_GetMode( processName )
}
WinGetTitle, title, A
StringReplace, tt,tt, $processName$, %processName%, A
StringReplace, tt,tt, $title$, %title%, A
StringReplace, tt,tt, $mode$, %mode%, A
StringReplace, tt,tt, $modeType$, % _SendU_Get_Mode_Type( mode ), A
StringReplace, tt,tt, $modeName$, % _SendU_Get_Mode_Name( mode ), A
ToolTip, %tt%
SetTimer, _SendU_Remove_Tooltip, 2000
return
_SendU_Remove_Tooltip:
SetTimer, _SendU_Remove_Tooltip, Off
ToolTip
return
}
_SendU_Dynamic_Mode( processName, clearPrevProcess = -1 )
{
static prevProcess := "fOyj9b4f79YmA7sZRBrnDbp75dGhiauj" ; Nothing
static mode := ""
if ( clearPrevProcess == 1 )
prevProcess := "fOyj9b4f79YmA7sZRBrnDbp75dGhiauj" ; Nothing
if ( processName == prevProcess )
return mode
prevProcess := processName
mode := _SendU_GetMode( processName )
if ( mode == "" )
mode = i
return mode
}
; http://www.autohotkey.com/forum/topic17838.html
_SendU_SetMode( sKey, sItm )
{
static pdic := 0
if ( pdic == 0 )
_SendU_Get_Dictionary( pdic )
pKey := SysAllocString(sKey)
VarSetCapacity(var1, 8 * 2, 0)
EncodeInteger(&var1 + 0, 8)
EncodeInteger(&var1 + 8, pKey)
pItm := SysAllocString(sItm)
VarSetCapacity(var2, 8 * 2, 0)
EncodeInteger(&var2 + 0, 8)
EncodeInteger(&var2 + 8, pItm)
DllCall(VTable(pdic, 8), "Uint", pdic, "Uint", &var1, "Uint", &var2)
SysFreeString(pKey)
SysFreeString(pItm)
}
; http://www.autohotkey.com/forum/topic17838.html
_SendU_GetMode( sKey )
{
static pdic := 0
if ( pdic == 0 )
_SendU_Get_Dictionary( pdic )
pKey := SysAllocString(sKey)
VarSetCapacity(var1, 8 * 2, 0)
EncodeInteger(&var1 + 0, 8)
EncodeInteger(&var1 + 8, pKey)
DllCall(VTable(pdic, 12), "Uint", pdic, "Uint", &var1, "intP", bExist)
If bExist
{
VarSetCapacity(var2, 8 * 2, 0)
DllCall(VTable(pdic, 9), "Uint", pdic, "Uint", &var1, "Uint", &var2)
pItm := DecodeInteger(&var2 + 8)
Unicode2Ansi(pItm, sItm)
SysFreeString(pItm)
}
SysFreeString(pKey)
Return sItm
}
_SendU_Get_Dictionary( ByRef mypdic )
{
static pdic := 0
if ( pdic == 0 ) {
; http://www.autohotkey.com/forum/topic17838.html
CoInitialize()
CLSID_Dictionary := "{EE09B103-97E0-11CF-978F-00A02463E06F}"
IID_IDictionary := "{42C642C1-97E1-11CF-978F-00A02463E06F}"
pdic := CreateObject(CLSID_Dictionary, IID_IDictionary)
DllCall(VTable(pdic, 18), "Uint", pdic, "int", 1) ; Set text mode, i.e., Case of Key is ignored. Otherwise case-sensitive defaultly.
}
mypdic := pdic
}
_SendU_Load_Dynamic_Modes()
{
_SendU_SetMode( "totalcmd.exe", "c" )
_SendU_SetMode( "skype.exe", "c" )
}
; --------------------- other functions ----------------------------
_SendU_SetVar( var, value )
{
global
_SendU_%var% := value
}
_SendU_GetVar( var )
{
global
return _SendU_%var% . ""
}
_SendU_Default_Value( var, value )
{
global
if ( _SendU_%var% . "" == "" )
_SendU_%var% := value
}
_SendU_Load_Locale()
{
stringLower, lang, A_Language
if ( lang == "040e" ) { ; Hungarian
_SendU_Default_Value("DYNAMIC_MODE_TOOLTIP", "Új mód a(z) $processName$ programhoz`n($title$)`n ""$mode$"" ($modeName$ - $modeType$)")
_SendU_Default_Value("Mode_Name_i", "SendInput")
_SendU_Default_Value("Mode_Name_c", "Vágólap")
_SendU_Default_Value("Mode_Name_r", "Vágólap helyreállítással")
_SendU_Default_Value("Mode_Name_a", "Alt+Számbillentyuzet")
_SendU_Default_Value("Mode_Name_d", "Dinamikus")
_SendU_Default_Value("Mode_Name_0", "Ismeretlen")
_SendU_Default_Value("Mode_Type_i", "a legjobb, ha muködik")
_SendU_Default_Value("Mode_Type_c", "törli a vágólapot")
_SendU_Default_Value("Mode_Type_r", "talán lassú")
_SendU_Default_Value("Mode_Type_a", "talán nem muködik")
_SendU_Default_Value("Mode_Type_d", "programoktól függo dinamikus mód")
_SendU_Default_Value("Mode_Type_0", "ismeretlen mód")
} else { ; English -- please, correct my mispellings!
_SendU_Default_Value("DYNAMIC_MODE_TOOLTIP", "New mode for $processName$`n($title$)`nis ""$mode$"" ($modeName$ - $modeType$)")
_SendU_Default_Value("Mode_Name_i", "SendInput")
_SendU_Default_Value("Mode_Name_c", "Clipboard")
_SendU_Default_Value("Mode_Name_r", "Restore Clipboard")
_SendU_Default_Value("Mode_Name_a", "Alt+Numbers")
_SendU_Default_Value("Mode_Name_d", "Dynamic")
_SendU_Default_Value("Mode_Name_0", "Unknown")
_SendU_Default_Value("Mode_Type_i", "the best, if works")
_SendU_Default_Value("Mode_Type_c", "clears the clipboard")
_SendU_Default_Value("Mode_Type_r", "maybe slow")
_SendU_Default_Value("Mode_Type_a", "maybe not work")
_SendU_Default_Value("Mode_Type_d", "dynamic mode for the programs")
_SendU_Default_Value("Mode_Type_0", "unknown mode")
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; LABELS AND INCLUDES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
_SendU_Try_Dynamic_Mode:
_SendU_Change_Dynamic_Mode:
SendU_Try_Dynamic_Mode()
return
_SendU_Toggle_Clipboard_Restore_Mode:
SendU_Clipboard_Restore_Mode( 2 )
_SendU_Dynamic_Mode_Tooltip()
return
*/
#include CoHelper.ahm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END OF SENDU MODULE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;