 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
tazmanian
Joined: 17 Nov 2007 Posts: 16
|
Posted: Sat Nov 17, 2007 7:55 pm Post subject: I cant get a script to work -- a compiler/interpreter issue? |
|
|
I have been autoscript for a few days now and I wrote a script which does something fairly trivial. When you press capslock you are put into a mode wherein you can press x to cut, c to copy, v to paste, d to delete and e to enter. I was going to add functions to other keys which are on the left hand side of the keyboard.
I wrote the script because when you use the mouse with the right hand you want the left hand to be able to press enter and delete things.
I disabled keys which are not defined in this mode, such as for example q, and that is what the pressUndefinedLetter method is all about.
Anyway, the problem is that if I switch on capslock by pressing shift+caplock and then press "t" then it will give me a small t and the caplock button flashes on and off. It does this with other letters too. I honestly cannot figure out why. In fact it worked at one point and I have made minor edits since.
At one point it was working though...
| Code: |
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; ***********************************************
; *********** Mouse Mode ************************
; ***********************************************
BEGIN:
Initialise()
Initialise()
{
global MouseMode = false
}
$+CapsLock::CapsLock
$CapsLock::
ChangeMode()
return
ChangeMode()
{
global
if MouseMode = true
{
MouseMode = false
}
else
{
MouseMode = true
}
Progress, y900 zh0 b fs18, MouseMode: %MouseMode%
sleep 300
Progress, Off
}
$d::
pressd()
return
$e::
presse()
return
$x::
pressx()
return
$c::
pressc()
return
$v::
pressv()
return
; undefined letters just just for letters that appear under the left hand
$q::
pressUndefinedLetter("q")
return
$w::
pressUndefinedLetter("w")
return
$r::
pressUndefinedLetter("r")
return
$t::
pressUndefinedLetter("t")
return
$a::
pressUndefinedLetter("a")
return
$s::
pressUndefinedLetter("s")
return
$f::
pressUndefinedLetter("f")
return
$g::
pressUndefinedLetter("g")
return
$z::
pressUndefinedLetter("z")
return
$b::
pressUndefinedLetter("b")
return
pressd()
{
global
if MouseMode = true
{
Send {Delete}
}
else
{
Send d
}
}
presse()
{
global
if MouseMode = true
{
Send {Enter}
}
else
{
Send e
}
}
pressx()
{
global
if MouseMode = true
{
Send ^x
}
else
{
Send x
}
}
pressc()
{
global
if MouseMode = true
{
Send ^c
}
else
{
Send c
}
}
pressv()
{
global
if MouseMode = true
{
Send ^v
}
else
{
Send v
}
}
pressUndefinedLetter(param)
{
global
if MouseMode = true
{
; this is somehow necessary
}
else
{
Send %param%
}
}
|
|
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1501
|
Posted: Sat Nov 17, 2007 9:43 pm Post subject: |
|
|
Firstly, I would like to encourage you to think of AHK as being less like c++ and more like basic in the way its code reads. The only thing I mean here is that a large number of function-blocks and tight control is not necessary and it makes visual debugging harder.
Secondly, I would like you to try using | Code: | GetKeyState, state, CapsLock, T ; D if CapsLock is ON or U otherwise.
| instead of having a seperate variable for capslock state.
Thirdly, I would suggest that you condense your code for readability purposes.
[edit:] | Code: | string = qwertasdfgzxcvb ; keys to block
ctrlkeys = xcvz ; keys which get modified
#Singleinstance, Force
Sendmode, Event
GetKeyState, state, CapsLock, T
MouseMode = Off
if state = D
{
MouseMode = On
loop
{
StringLeft, tempk, string, 1
StringTrimLeft, string, string, 1
if tempk =
break
HotKey, *%tempk%, DoTheThing
}
}
Progress, y900 zh0 b fs18, MouseMode: %MouseMode%
sleep 300
Progress, Off
return
*~Capslock::reload
DoTheThing:
StringRight, tempk, a_thishotkey, 1
IfInString, ctrlkeys, %tempk%
send {blind}^{%tempk%}
If tempk = e
send {blind}{enter}
If tempk = d
send {blind}{delete}
return |
_________________ My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags ! |
|
| Back to top |
|
 |
tazmanian
Joined: 17 Nov 2007 Posts: 16
|
Posted: Sun Nov 18, 2007 6:28 pm Post subject: |
|
|
VxE
I found your code very beautiful
Below is your code which I modified so that it does not reload each time you press caps lock. I like your idea of using the caps lock key because of the use of the light on the keyboard.
Anyway, how would I type things in all caps without the use of the caps lock key which is now taken over by the script?
| Code: |
ctrlKeys = xcv ; Keys which are to be control + key
CONFIGUREKEYS:
allKeys = qwertyuiopasdfghjklzxcvbnm
GetKeyState, state, CapsLock, T
loop
{
if allKeys = ; empty
{
break
}
StringLeft, tempk, allKeys, 1
StringTrimLeft, allKeys, allKeys, 1
if state = D
{
HotKey, *%tempk%, PRESSLETTER, On
}
else
{
HotKey, *%tempk%, Off, UseErrorLevel
}
}
return
*~Capslock::
Goto, CONFIGUREKEYS
return
PRESSLETTER:
StringRight, tempk, a_thishotkey, 1
IfInString, ctrlKeys, %tempk%
send {blind}^{%tempk%}
If tempk = e
send {blind}{enter}
If tempk = d
send {blind}{delete}
return
|
|
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Mon Nov 19, 2007 1:05 am Post subject: |
|
|
map +Capslock to capslock, or change the script to use scrollLock.
You actually need the caplock key for something? _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|