I'm using Barrier to control a Windows machine from macOS, and I would like to remap Windows key to Command key to perform more efficient shortcuts.
Traditionally, simple one line statements (e.g. #c::Send ^c) will work, but have one shortcomming: if you hold pressing Command key then press "c" repeatly, you won't get repeating copy actions as expected, you will get one copy action and multiple typing of "c"s, which is annoying and not as natural as genuine "Command+C".
In order to have real "Command+C" & "Command+V" experience (& many other shortcuts perfectly remapped), I figured out a more complex (but working) apporach:
LWin & c::
StateWindowsPressC := true
Send {Ctrl Down}c
#If (StateWindowsPressC)
~*LWin Up::
Send {Ctrl Up}
StateWindowsPressC := false
return
#If
LWin & v::
StateWindowsPressV := true
Send {Ctrl Down}v
#If (StateWindowsPressV)
~*LWin Up::
Send {Ctrl Up}
StateWindowsPressV := false
return
#If
Please note that variables like StateWindowsPressC and StateWindowsPressV should not be the same name or they will cause chaos.
These statements work, but have too many duplicate statements, is there any way to encapsule them into functions?
Related
I am trying to make an AutoHotKey script to smoothen up my After Effects workflow. The deal is i have to make a keyframe, then go 5 keyframes ahead, this ultimately takes me 9 keypresses to do! So I tried to cut this down to just 3.
This is my code:
^+1::
Send, ^ & ! & + & {F1}
Send, ^ & {Right}
Send, ^ & {Right}
Send, ^ & {Right}
Send, ^ & {Right}
Send, ^ & {Right}
return
I want it to press
ctrl+shift+alt+F1 then ctrl+right_arrow 5 times.
What am i missing?
SOLUTION:
So I also asked this question on Reddit, where a user told me that the "Send," command is very literal, so it ended up typing " ^ & {Right}" and " ^ & ! & + & {F1}" in letters, furthermore it was unnecessary to type a & and the spaces between the others, which I also found out using a keyboard tester. So the solution was to type:
^+1::
Send ^!+{F1}
Send ^{Right}
Send ^{Right}
Send ^{Right}
Send ^{Right}
Send ^{Right}
return
For commands do not use the comma after send (this is for text only)
SendInput {ctrl DOWN}{Left 5}{CTRL UP}
This is one method. Rinse and repeat for the other keys, like shift.
Another method is an exclamation point for alt, a cap for ctrl, and a plus for shift.
SendInput ^!+{left 5}
According to the post below, I guess adding a comma converts to send raw? But I'm not sure if that's true. I'll test it out later.
You could also make a function, like a loop or whatever. That might be fun. Pass the keys and the number of times to push them as parameters. Coding challenge!
I am writing scripts for automate 'make menuconfig'.
I want to use down arrow key to select some items in the dialog.
My down arrow key in terminal is '^[[B'.
So I use send "\033[B", send "\x1b\x5b\x42", send "\1B[B", etc. in expect script,
but none is working.
#!usr/bin/expect
spawn make menuconfig
send "v" #select item hot key
send "y" #enter this item
send "\033\[B" #I expect the down arrow key will execute here.
interact
exit 0
How could I do?
Or does this not work in expect?
Is there other method to automate do this?
I'm trying to read a character instantly from command line without use of Enter. The ruby (ruby 1.9.3p374) code that I'm using is the following:
require 'io/console'
ch = STDIN.getch
puts ch
until now everithing is working fine but now i want to put this code inside an infinite loop doing some other stuff, something like
loop do
puts "..doing stuff.."
ch = STDIN.getch
if ch == 'q'
break
end
end
but this code always force that we press a key between each printing. I want a behaviour similar to STDIN.read_nonblock method but without having to press enter key after pressing one char.
Basically I want to print "..doing stuff.." until I press a certain key on keyboard but i don't want to use enter.
Any help will be appreciated. Thanks
You could always use the built-in curses library to handle your interaction. It's very powerful and is used to construct keyboard-driven tools such as text editors.
The alternative is to use select to poll if STDIN is readable. Your terminal might be in a line-buffered state, so you'd need to adjust that before single keystrokes are received. This is something that Curses can handle for you.
I'm trying to read user input in a console interface in a Lua application.
However, I do not want to halt program execution as the title suggests. Using read() would interfere with the normal handling of ongoing events, and interface updates, while the user's typing.
The best solution I could come up with was maintaining a temporary variable I apply any user input to that isn't a function key. However, my event handler returns scancodes, and I know of no way to map these to ASCII codes short of maintaining a table for each key, which is something I really want to avoid.
Any ideas?
Edit
To give an example of what I mean:
function read_input()
local input = read()
do_something_with(input)
end
while true do
e,param1,param2,param3 = os.pullEvent()
if (e=='key' and param1=='201') then
read_input()
elseif (e=='something_else') then
do_something_else()
end
end
As you can see, the user can at some point land in a function demanding user input. While this input is taken, I can't have any other (event-based) functions of the program being impeded by this.
You would need to read the keys continuously from the os.pullEvent()
local input
while true do
e,param1,param2,param3 = os.pullEvent()
if (e=='key') then
-- do some fancy stuff for checking which key has pressed and append it to input
-- additionally if it's enter do something other fancy
else
-- blah blah
end
end
I'm not sure but I thought the character of which key was pressed is in one of the params of the pullEvent, I might be mistaken tho.
Additionally if you want to do something every second or so, start a timer which also fires the pullEvent.
I am trying to use WScript.Shell SendKeys method to emulate sending a key press from the Number Pad.
I have an application that I am writing automated testing for using QTP. It is a Web Browser based application and the input is into a Java App within the web page. The input only accepts key presses from the Number Pad and the Enter key.
So far I am using this code:
Dim strInputKey
strInputKey = "{ENTER}"
Set objWsh = CreateObject("WScript.Shell")
Browser("Launch Browser").Page("Test Application").WebElement("Item ID").Click
objWsh.SendKeys strInputKey
This works fine for sending the Enter key, but I can't quite figure out if there is a way to send Number Keys. Any help would be greatly appreciated.
I am not sure if there are any undocumented ways of achieving this. I have read http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx but it doesn't go into great detail.
I don't have the rep to comment on the above answer that said
objWsh.SendKeys chr(79) & chr(80) & chr(81)
but I don't think it's correct
objWsh.SendKeys chr(79) & chr(80) & chr(81)
For a start, it sends the letters O,P,Q
And he wants numbers, like 1234567890
and the link goes to keyboard scan codes.. I think those are for knowing what key on the keyboard was pressed. They are different from ascii codes.
79,80,81 are the keyboard scan codes for some numbers on the number pad / numpad.
Chr though, uses ascii codes. not keyboard scan codes.
Furthermore, just specifying a digit, here, since it isn't done by pressing a key, it doesn't specify and needn't specify, which was key was used, since a key wasn't used.
To sendkeys some numbers (from the number pad), is just same as sending keys from the top row. You just want to send some numbers.
If all he wants to know is how to use sendkeys to send digits, then obviously.
objWsh.SendKeys 12345
or
str="12345"
objWsh.SendKeys str
But if the questioner didn't realise that objWsh.SendKeys 12345 would do it, then perhaps the questioner is just confused. I guess from the green tick, he voted an answer that is like objWsh.SendKeys "OPQ".
I am aware that this is an old question, but for the sake of haing correct questions and answers..
You'll need to use the keycodes for the number pad.
Here's a list of them:
http://www.empirisoft.com/directrt/help/_helpcontents.htm?directrt_key_codes.htm
So to send "123", you would need to do:
objWsh.SendKeys chr(79) & chr(80) & chr(81)