Shift键训练轮和Shift括号重新映射

时间:2013-07-14 22:47:47

标签: autohotkey

我希望使用AutoHotKey来修改我的shift键的功能。该功能在Steve Losh的博客条目here中有所描述。具体来说,我喜欢我的移位键来执行以下操作:

  • 如果在短时间内按下并释放 LShift RShift 而没有按下其他键,则发送()分别。
  • 如果 LShift RShift 是"滚动"在300ms以内一起(按 LShift ,按 RShift ,释放 LShift ,释放 RShift 等),发送())(
  • 如果使用移位键不正确 LShift S RShift K < / kbd>等)然后没有任何反应。

我一直遇到300ms要求的问题以及&#34;滚动&#34;功能。具体来说,我只能检测到由于热键组合而释放密钥的时间,例如:

LShift &  0:: return

这是我到目前为止所处的位置:

LShift::
    Send {LShift Down}
    KeyWait, LShift
    Send {LShift Up}
    if (A_TimeSinceThisHotkey < 300){
        if (A_PriorKey = "LShift")
        {
            Send {)}
        }
    }
return

4 个答案:

答案 0 :(得分:2)

我认为没有理由使用300毫秒的超时,这似乎是不可靠和不必要的 看看这个注释代码,它简短而有效,似乎满足您的所有要求:

LShift::Send, (
RShift::Send, )
LShift & RShift:: Send, ()
RShift & LShift:: Send, )(

/* Put your unwanted combinations here
 * and let them do nothing
*/
LShift & q::return
RShift & y::return

修改
由于LShift和RShift已经是前缀热键,我遗漏了here所描述的技巧。

答案 1 :(得分:0)

我觉得不得不想出这个。你走了!

我基本上为每个 Shift + Letter 组合键创建了一个热键,以便发送正确的密钥案例并设置Abort值。然后,只要按下 Shift 键之一,就会引用Abort值,以确定是否发送相应的)< / KBD>

“滚动”是通过为 LShift + RShift (相反)创建一个热键来完成的。然后,它会查看首先发布哪个密钥以确定())(

如果这是你想要的,请接受!

Loop 26
{
    Hotkey, % "~LShift & " Chr(A_Index+96), LetterKey ; Hotkeys for A-Z
    Hotkey, % "~RShift & " Chr(A_Index+96), LetterKey ; Hotkeys for A-Z
}
Return

RShift::
LShift::
    Abort := 0
    keyDown := A_TickCount
    Keywait, % A_ThisHotkey
    duration := A_TickCount - keyDown
    If (duration < 200) and (Abort = 0)
        SendInput % (A_ThisHotkey = "LShift") ? "(" : ")"
    Send {LShift Up}
    Return

RShift & LShift::
LShift & RShift::
    Keywait, LShift
    If GetKeyState("RShift", "P")
    {
        Keywait, RShift
        Send ()
    }
    Else
        Send )(
    Return

LetterKey:
    SendInput, % "+" SubStr(A_ThisHotKey, 0, 1)
    Abort := 1
Return

修改 嗯,我似乎和你有同样的问题。由于热键,我的持续时间总是为0。

答案 2 :(得分:0)

MCL的答案很接近,但是当我测试它时,我发现按住Shift键并没有选择文字。这是一个带有直通的版本,允许按住Shift键点击工作。

;shift to parens
LShift::Send, (
RShift::Send, )
LShift & RShift:: Send, ()
RShift & LShift:: Send, )(

;passthrough for shift-click
LShift & LButton::
  Send, {LShift Down}{LButton}
  Send, {LShift Up}
RShift & LButton::
  Send, {RShift Down}{LButton}
  Send, {RShift Up}

如果没有对autohotkey的实现或对autohotkey的实际修改有非常深刻的理解,我认为300ms超时是不可能的。当我尝试让它工作时(使用http://www.autohotkey.com/board/topic/98742-remapping-shift-key/),我发现A_PriorHotkey并未始终填充。我不认为该变量是以这种方式使用修饰键。

答案 3 :(得分:0)

我在AutoHotKey论坛上找到并修改了this script。 (原始剧本很容易输入&#34; K(&#34;当你打算键入&#34; K&#34;如果你输入太快,那么我已经修改了它以便不应该&#39;不再发生了)

    class MyList {

    private static int counter;
    private Node head;

    // Default constructor
public MyList() {

}

// appends the specified element to the end of this list.
public void add(Student data) {
// Initialize Node only incase of 1st element
if (head == null) {
head = new Node(data);
}

Node temp = new Node(data);
Node current = head;

// Check for NPE before iterate over current
if (current != null) {
// starting at the head node, crawl to the end of the list and then add element after last node
while (current.getNext() != null) {
current = current.getNext();
}
// the last node's "next" reference set to our new node
current.setNext(temp);
}

// increment the number of elements variable
incrementCounter();
}

private static int getCounter() {
return counter;
}

private static void incrementCounter() {
counter++;
}

private void decrementCounter() {
counter--;
}

// inserts the specified element at the specified position in this list
public void add(Student data, int index) {
Node temp = new Node(data);
Node current = head;

// Check for NPE before iterate over current
if (current != null) {
// crawl to the requested index or the last element in the list, whichever comes first
for (int i = 0; i < index && current.getNext() != null; i++) {
current = current.getNext();
}
}

// set the new node's next-node reference to this node's next-node reference
temp.setNext(current.getNext());

// now set this node's next-node reference to the new node
current.setNext(temp);

// increment the number of elements variable
incrementCounter();
}

public Student get(int index)
// returns the element at the specified position in the list.
{
// index must be 1 or higher
if (index <= 0)
return null;
Node current = null;
if (head != null) {
current = head.getNext();
for (int i = 0; i < index; i++) {
if (current.getNext() == null)
return null;
current = current.getNext();
}
return current.getData();
}
return current.getData();
}

// removes the element at the specified position in this list.
public boolean remove(int index) {

// if the index is out of range, exit
if (index < 1 || index > size())
return false;

Node current = head;
if (head != null) {
for (int i = 0; i < index; i++) {
if (current.getNext() == null)
return false;

current = current.getNext();
}
current.setNext(current.getNext().getNext());

// decrement the number of elements variable
decrementCounter();
return true;

}
return false;
}

// returns the number of elements in this list.
public int size() {
return getCounter();
}

public String toString() {
String output = "";

if (head != null) {
Node current = head.getNext();
while (current != null) {
output += "[" + current.getData().toString() + "]";
current = current.getNext();
}

}
return output;
}

private class Node {
// reference to the next node in the chain
Node next;

// data carried by the node
Student data;

// Node constructor
public Node(Student dataValue) {
next = null;
data = dataValue;
}

// another Node constructor to specify the node to point to.
@SuppressWarnings("unused")
public Node(Student dataValue, Node nextValue) {
next = nextValue;
data = dataValue;
}

public Student getData() {
return data;
}

@SuppressWarnings("unused")
public void setData(Student dataValue) {
data = dataValue;
}

public Node getNext() {
return next;
}

public void setNext(Node nextValue) {
next = nextValue;
}

}
}