Jim Dunn wrote: ↑01 Oct 2020, 11:05
No, you're right, my error, sorry - I double pasted some stuff.
For an easier comparison, could you please paste in two code boxes:
(1) What is working (your existing script before you tried to add this stuff)
(2) The exact version you revised that isn't working
In their entirety.
Thanks
(1) my original working script...
Code: Select all
setstorecapslockmode, off
setcapslockstate, off
#inputlevel 1
hotkey, e, off
hotkey, r, off
capslock::vkFF ;remaps capslock into unassigned vkFF
#inputlevel 0 ;instead of "capslock & ..." use "vkFF & ..."
vkFF & 0:: ;turns capslock on and off
setcapslockstate % !getkeystate("capslock", "t")
return
#maxhotkeysperinterval 200
#hotkeyinterval 100
setbatchlines, -1
setkeydelay, -1
vkFF & e::
sendInput {wheelup}
hotkey, e, on
settimer, block_e, 300
return
e::
return
block_e:
hotkey, e, off
settimer, block_e, off
return
vkFF & r::
sendInput {wheeldown}
hotkey, r, on
settimer, block_r, 300
return
r::
return
block_r:
hotkey, r, off
settimer, block_r, off
return
!up::soundset +2
return
!down::soundset -2
return
vkFF & a::
ifwinexist, ahk_class CabinetWClass
winclose
else
run c:\users\lovejoy\downloads, , max
return
vkFF & w::
run c:\users\lovejoy\downloads\type10.txt, , max
winwait, ahk_class Notepad
winactivate, ahk_class Notepad
return
vkFF & t::sendinput {volume_mute}
return
vkFF & y::
detecthiddenwindows on
settitlematchmode 2
ifwinexist, SafeVisit
winclose
else
run c:\users\lovejoy\downloads\safevisit\safevisit.exe, , hide
return
#ifwinactive, ahk_class CabinetWClass
~mbutton::send !{up}
return
#ifwinactive
#ifwinactive, ahk_class Chrome_WidgetWin_1
vkFF & enter::send !{enter}
return
#ifwinactive
IME_CHECK(WinTitle)
{
WinGet,hWnd,ID,%WinTitle%
Return Send_ImeControl(ImmGetDefaultIMEWnd(hWnd),0x005,"")
}
Send_ImeControl(DefaultIMEWnd, wParam, lParam)
{
DetectSave := A_DetectHiddenWindows
DetectHiddenWindows,ON
SendMessage 0x283, wParam,lParam,,ahk_id %DefaultIMEWnd%
if (DetectSave <> A_DetectHiddenWindows)
DetectHiddenWindows,%DetectSave%
return ErrorLevel
}
ImmGetDefaultIMEWnd(hWnd)
{
return DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)
}
vkFF & o::
sleep 50
ret := ime_check("a")
if %ret% = 0
{
send, {vk15}
}
return
vkFF & p::
sleep 50
ret := ime_check("a")
if %ret% <> 0
{
send, {vk15}
}
return
vkFF & lbutton::
if a_cursor = ibeam
{
send, {click}^a
sleep 50
ret := ime_check("a")
if %ret% = 0
{
send, {vk15}
}
}
else
{
send {lbutton}
}
return
vkFF & rbutton::
if a_cursor = ibeam
{
send, {click}^a
sleep 50
ret := ime_check("a")
if %ret% <> 0
{
send, {vk15}
}
}
else
{
send {rbutton}
}
return
(2) the combined script that isn't working + error code
Code: Select all
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance force
winTitle := "ahk_class Notepad"
!x::ExitApp
OnActivate(hActivation:=-1) { ; https://docs.microsoft.com/en-us/windows/win32/menurc/using-cursors#confining-a-cursor
local
static rcOldClip := ""
static hOldActivation := ""
if (hActivation) {
((hActivation <> -1) && hOldActivation:=hActivation)
VarSetCapacity(rcOldClip, 16, 0) ; previous area for ClipCursor
DllCall("User32.dll\GetClipCursor", "Ptr", &rcOldClip) ; Record the area in which the cursor can move.
VarSetCapacity(rcClip, 16, 0) ; new area for ClipCursor
DllCall("User32.dll\GetWindowRect", "Ptr", hOldActivation, "Ptr", &rcClip) ; Get the dimensions of the application's window.
DllCall("User32.dll\ClipCursor", "Ptr", &rcClip) ; Confine the cursor to the application's window.
SetTimer % A_ThisFunc, 100
} else {
SetTimer % A_ThisFunc, Off
(rcOldClip && DllCall("User32.dll\ClipCursor", "Ptr", &rcOldClip), rcOldClip:="") ; Restore the cursor to its previous area.
}
}
; =====================================
shellMessage(wParam, lParam) { ; based on https://autohotkey.com/board/topic/80644-how-to-hook-on-to-shell-to-receive-its-messages/
local
global winTitle
static f := (Func("OnActivate")
, DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd)
, OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "shellMessage")
, OnExit("shellMessage"))
static iRcOldClip := ""
static _ := (VarSetCapacity(iRcOldClip, 16, 0) ; the very initial area for ClipCursor
, DllCall("User32.dll\GetClipCursor", "Ptr", &iRcOldClip)) ; Record the initial area in which the cursor can move.
Critical
if (wParam = A_ExitReason) {
return 0, DllCall("DeregisterShellHookWindow", "UInt", A_ScriptHwnd), DllCall("User32.dll\ClipCursor", "Ptr", &iRcOldClip) ; Restore the cursor to its very initial area.
}
if ((wParam = 32772) or (wParam = 4)) { ; HSHELL_WINDOWACTIVATED := 4, HSHELL_RUDEAPPACTIVATED := 32772
fn := f.bind(WinActive(winTitle))
SetTimer % fn, -1
}
}
;and here comes my script
setstorecapslockmode, off
setcapslockstate, off
#inputlevel 1
hotkey, e, off
hotkey, r, off
capslock::vkFF ;remaps capslock into unassigned vkFF
#inputlevel 0 ;instead of "capslock & ..." use "vkFF & ..."
vkFF & 0:: ;turns capslock on and off
setcapslockstate % !getkeystate("capslock", "t")
return
#maxhotkeysperinterval 200
#hotkeyinterval 100
setbatchlines, -1
setkeydelay, -1
vkFF & e::
sendInput {wheelup}
hotkey, e, on
settimer, block_e, 300
return
e::
return
block_e:
hotkey, e, off
settimer, block_e, off
return
vkFF & r::
sendInput {wheeldown}
hotkey, r, on
settimer, block_r, 300
return
r::
return
block_r:
hotkey, r, off
settimer, block_r, off
return
!up::soundset +2
return
!down::soundset -2
return
vkFF & a::
ifwinexist, ahk_class CabinetWClass
winclose
else
run c:\users\lovejoy\downloads, , max
return
vkFF & w::
run c:\users\lovejoy\downloads\type10.txt, , max
winwait, ahk_class Notepad
winactivate, ahk_class Notepad
return
vkFF & t::sendinput {volume_mute}
return
vkFF & y::
detecthiddenwindows on
settitlematchmode 2
ifwinexist, SafeVisit
winclose
else
run c:\users\lovejoy\downloads\safevisit\safevisit.exe, , hide
return
#ifwinactive, ahk_class CabinetWClass
~mbutton::send !{up}
return
#ifwinactive
#ifwinactive, ahk_class Chrome_WidgetWin_1
vkFF & enter::send !{enter}
return
#ifwinactive
IME_CHECK(WinTitle)
{
WinGet,hWnd,ID,%WinTitle%
Return Send_ImeControl(ImmGetDefaultIMEWnd(hWnd),0x005,"")
}
Send_ImeControl(DefaultIMEWnd, wParam, lParam)
{
DetectSave := A_DetectHiddenWindows
DetectHiddenWindows,ON
SendMessage 0x283, wParam,lParam,,ahk_id %DefaultIMEWnd%
if (DetectSave <> A_DetectHiddenWindows)
DetectHiddenWindows,%DetectSave%
return ErrorLevel
}
ImmGetDefaultIMEWnd(hWnd)
{
return DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)
}
vkFF & o::
sleep 50
ret := ime_check("a")
if %ret% = 0
{
send, {vk15}
}
return
vkFF & p::
sleep 50
ret := ime_check("a")
if %ret% <> 0
{
send, {vk15}
}
return
vkFF & lbutton::
if a_cursor = ibeam
{
send, {click}^a
sleep 50
ret := ime_check("a")
if %ret% = 0
{
send, {vk15}
}
}
else
{
send {lbutton}
}
return
vkFF & rbutton::
if a_cursor = ibeam
{
send, {click}^a
sleep 50
ret := ime_check("a")
if %ret% <> 0
{
send, {vk15}
}
}
else
{
send {rbutton}
}
return
it returns errors 7 times:
Warning: This line will never execute, due to Return preceeding it.
051: SetStoreCapslockMode,off
064: SetBatchLines,-1
096: Return
099: Return
115: Return
128: Return
133: Return