How to trigger an action if there's only one key being pressed? - scripting

Here's my current script:
Shift::Send ^{Space}
It doesn't only trigger ^{Space} on pressing Shift alone, it also triggers on Alt+Shift (just these two keys) and Ctrl+Shift (just these two keys) if Shift is the last released, is there a way to trigger ^{Space} if Shift is the only key being pressed?
AutoHotkey Version: 1.1.33.09.

I have your answer and to think I only learned this today.
~Shift::return
#If, A_PriorHotkey = "~Shift"
Shift Up::
SendEvent, ^{space}
#If
return
Worked for me. The ' ~ ' symbol will let you still type capitals although it will still send the ^{space} still. Either delete it (it still works) and/or You will have to make this script Context-sensitive right?
P.s.
I learned it from another code and just adapted it to my and your needs. I needed almost the same thing as you today :-)
Here is the old code I found which I adapted
^k::return
#If, A_PriorHotkey = "^k"
^a::ToolTip, % A_ThisHotkey " pressed with ^k"
^b::ToolTip, % A_ThisHotkey " pressed with ^k"
^c::ToolTip, % A_ThisHotkey " pressed with ^k"
^d::ToolTip, % A_ThisHotkey " pressed with ^k"
^k up::SendInput, ^k
#If

This works for me.
~Shift::return
#If, A_PriorHotkey = "~Shift"
Shift Up::SendEvent, foo
!*c::SendEvent, foo
#If
return

try this:
Shift::
SendEvent, foo
return
Ctrl & Shift::return
Alt & Shift::return
This doesn't work with Numpad keys though for some reason. And again, this script will have to be Context-sensitive.

Here's my working script:
~*Alt::
~*Ctrl::
~*Shift::return
Shift::SendEvent ^{Space}

Yup Simple, Put the '~ Tilda' key next to it.
~Shift::
SendEvent, ^{Space}
return

Related

How to send an addition sequence after an input without interferring other combination with it?

I want whenever a LButton, ^PgUp or ^PgDn is active, it should also send an addition sequence after it. From Function hotkeys and A_ThisHotkey I can use:
LButton::
PgUp::
PgDn::
Send {%A_ThisHotkey%}!wi
But then mouse drag is not functional anymore, and it's ^PgUp that should be re-assigned, not PgUp. But none of these works:
^PgUp::Send {%A_ThisHotkey%}!wi
PgUp::Send ^{%A_ThisHotkey%}!wi
^PgUp::Send ^{%A_ThisHotkey%}!wi
How to do this properly? My workaround is just to divide and rule:
^PgUp::Send ^{PgUp}!wi
^PgDn::Send ^{PgDn}!wi
But I like to use A_ThisHotkey for learning purpose.
Try:
~LButton Up::
~^PgUp Up::
~^PgDn Up::Send !wi

set up a shortcut / keybinding under GNU/Linux with altGr key (but Autokey nor other methods reconize the key)

I need to do a simple shortcut and this problem is driving me crazy.
Whenever I press AltGR+Backspace I would like to simulate a CTRL+LEFT(arrow).
The thing is that AutoKey doesn't get the AltGR input (and neither xbindkeys or other methods).
I tried to do it with xbindkeys but AltGr is seen as a "Mod5 + ISO_Level3_Shift" input and despite that I can't figure out how to do it, this doesn't work:
"xte 'keydown Control_L' 'keydown Left' 'keyup Control_L'"
m:0x80 + c:22
Mod5 + BackSpace
Thanks in advance for any help!
I find a solution with xbindkeys, I needed to insert "+ Release" after the combination of keys, so:
"xte 'keydown Control_L' 'key Left' 'keyup Control_L'"
Mod5 + BackSpace + Release

Octave printf does not output when followed by ginput

I am trying to make a prompt for the user to select from the figure (plot).
When I run it with the code below, the prompt doesnt display until i click on the figure, after which the prompt displays and the code continues. In fact, no call to printf (or disp) that is called before the ginput call displays until i select the figure.
printf("Select part\n"); % (disp also doesnt work properly)
[xinput,yinput] = ginput(1);
The purpose of the prompt is to alert the user to move to the figure, so naturally it needs to display before selecting the figure.
I can add an extra redundant input call between the two which forces the printf to display in the console. eg input("Press Enter"). but this is an inconvenient solution.
Strangely, if you run just the code above it does work normally. But when running in the remainder of the program it displays the issue. So it may be a difficult one to debug. Also, running it one line at a time in the full code using the debugger works properly, displaying the prompt before selecting the figure.
Just to add to the confusion. When running this part of the program in a loop, the first instance doesnt display the prompt correctly, but every other instance it works.
Thanks
EDIT:
The following code reliably fails (for me) in the same way my full program fails; (edited again to simplify)
figure(1);
input_test = input("press 1: ");
switch input_test
case 1
while true
clc;
printf("Left click to get coords or right click to finish\n");
[xinput,yinput,mouse_button] = ginput(1)
if mouse_button == 3
break
endif
endwhile
endswitch
It appears it has something to do with the line;
input_test = input("press 1: ");
If I replace this with
input_test = 1;
it works properly.
I dont know what is the reason for this, and I cannot remove the input request from this location.
Thanks Roger, you were correct, I did find a solution.
Using
fflush(stdout)
before the 'ginput' call solves the problem.
Found this in the 'input' help;
"Because there may be output waiting to be displayed by the pager,
it is a good idea to always call 'fflush (stdout)' before calling
'input'. This will ensure that all pending output is written to
the screen before your prompt."

Switch panes in Atom without cmd/ctrl + k?

I'd like to be able to switch between my Atom panes anytime without having to press CMD + K first before being able to switch via CMD + Up/Down/Left/Right.
Is this somehow possible?
I added this to the keymap but it doesn't work:
'atom-workspace':
'cmd-up': 'window:focus-pane-above'
'cmd-down': 'window:focus-pane-below'
'cmd-left': 'window:focus-pane-on-left'
'cmd-right': 'window:focus-pane-on-right'
This looks old, but incase anyone else stumbles on this - using the .editor context works for me:
'.editor':
'ctrl-alt-cmd-shift-right': 'window:focus-pane-on-right'
'ctrl-alt-cmd-shift-left': 'window:focus-pane-on-left'
'ctrl-alt-cmd-shift-up': 'window:focus-pane-above'
'ctrl-alt-cmd-shift-down': 'window:focus-pane-below'
Also, I wonder if using cmd-left/right would also cause an issue - on OSX cmd + left/right is a default OS shortcut for HOME / END (beginning / end of line), that might also cause a conflict.
'body':
'ctrl-right': 'window:focus-pane-on-right'
'ctrl-left': 'window:focus-pane-on-left'
This worked for left/right. I'm still trying to figure up and down tho
Check out the paner package! You can implement the usual-vim ctrl-w h etc. to move around panes by installing this and setting up the keymap. The documentation page has example keymaps.
Now if only they'd put a control key on both sides of the MacBook...
I ended up with:
'body':
'ctrl-alt left': 'window:focus-pane-on-left'
'ctrl-alt right': 'window:focus-pane-on-right'
'ctrl-alt up': 'window:focus-pane-above'
'ctrl-alt down': 'window:focus-pane-below'
press ctrl+alt, release, then hit your direction.

Simulate TAB keypress event in Selenium RC

I need to simulate a tab keypress in Selenium RC, using the Java API.
I do this after having entered some text using:
selenium.type(input, "mytext");
I've tried 3 alternatives to get the tab working:
selenium.keyPress(input, "\\9");
and:
selenium.focus(input);
selenium.keyPressNative("09");
and even:
selenium.getEval("var evt = window.document.createEvent('KeyboardEvent');evt.initKeyEvent ('keypress', true, true, window,0, 0, 0, 0,0, 9,0);window.document.getElementsByTagName('input')[2].dispatchEvent(evt);")
The best I can get is a "tab space" to be inserted after my text so I end up with this in the input field:
"mytext "
What I actually want is to tab to the next control. Any clues? Thanks!
(Note: I have to use tab and can not use focus or select to chose the element I want to go to, for various reasons, so no suggestions along these lines please!)
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB + "");
I don't use the Java API, but this post from google groups suggests it is your solution. I can't imagine that "9" is different from "09" in your question, but give it a try?
Try the official TAB char: \t or \u0009
Some functions may used Onblur. It will trigger the function when the field lose the key focus. here we can use fireEvent with "blur" or "focus" command as follows:
command: fireEvent
target: id=your_field_identification
value: blur
Reference: http://qaselenium.blogspot.com/2011/01/how-to-triger-tab-key-in-selenium.html
Improvising Ryley's answer, we can use
selenium.keyDownNative(java.awt.event.KeyEvent.VK_TAB + "");
selenium.keyUpNative(java.awt.event.KeyEvent.VK_TAB + "");
I tried this method for VK_CONTROL in IE and it worked good.
Use typeKeys():
Quoting the above link:
Unlike the simple "type" command, which forces the specified value into the page directly, this command may or may not have any visible effect, even in cases where typing keys would normally have a visible effect. For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in the field.
In some cases, you may need to use the simple "type" command to set the value of the field and then the "typeKeys" command to send the keystroke events corresponding to what you just typed.