How to Use Touch Gestures for Keyboard Devices - Autohotkey Script? - scripting

How can i Use Touch Gestures for Keyboard Devices - Autohotkey Script?
I want to Work Smarter on My Standard Keyboard Device, with INTELLIGENCE GESTURES KEYS MOVEMENTS
So that i do not need to move Both Hands to my Keyboard Device. (with this methodic i can Stay Always With my Hand on the Mouse Device)
On Touchscreens you have Gestures Tools, where you can do Multi Finger Taps to execute any Kind of Computer movements (Keyboard Shortcuts Macros), Why not do this on Keyboard Devices.
The AHK Script must can do this:
1 - [Click c] = Send c
2 - [Click 5x c] = Execute Script Part 5
3 - [Right Click v] + [Left Tap c] = send ^c ;Ctrl+c
4 - [Left Click c] + [Right Tap v] = send ^v ;Ctrl+v
5 - [Right Hold v] + [Left Tap c] = Execute Script Part 1
7 - [Left Hold c] + [Right Tap v] = Execute Script Part 2
8 - [Click c + v together (at the same time)] = Execute Script Part 3
9 - [Click x + c + v together (at the same time)] = Execute Script Part 4
My Ahk Script for Multi Clicks is:
Example1.ahk
#NoEnv
#SingleInstance force
;#NoTrayIcon
a1 := -1
b1 := 0
esc::exitapp ;You can click the (esc) key to stop the script.
;Use character ($) if you want to send hotkey itself ($c::send c)
;Click 5x C Key on keyboard, to Execute Ahk Code Part 5
$c::
if(a1 = -1)
{
a1 := 4
#Persistent
SetTimer, CountClicks, 100
}
else
{
a1 := 3
}
return
CountClicks:
if(a1 = 3)
{
b1 := b1 + 1
}
if(a1 = 0)
{
msgbox you did Click <C> Key > %b1%x times
if (b1=1)
{
;if Click 1x - Then Execute Ahk Code Part 1
;Here you can put any code for Part 1
;send c
}
if (b1=2)
{
;if Click 2x - Then Execute Ahk Code Part 2
;Here you can put any code for Part 2
}
if (b1=3)
{
;if Click 3x - Then Execute Ahk Code Part 3
;Here you can put any code for Part 3
Send {Volume_Mute} ;Send, Volume_Mute
}
if (b1=4)
{
;if Click 4x - Then Execute Ahk Code Part 4
;Here you can put any code for Part 4
}
if (b1=5)
{
;if Click 5x - Then Execute Ahk Code Part 5
;Here you can put any code for Part 5
}
b1 := 0
SetTimer, CountClicks , off
reload ; restart script
}
a1 := a1 - 1
return

Related

Why does this function not get called but after its his turn again it gets called this time

I am making a turn based game, currently I am trying to add a critical hit system it shows that it is doing critical hit damage but doesnt play the critical hit function,the thing that doesnt make sense too me is, it gets called when its his turn again so something in the first turn is making the function not be called but gets called at the second time, It seems to be who ever attacks first doesnt get the dialogue function to be called, but plays fine after the first turn.
func check_if_player(attacker, target):
if attacker == player_node:
print(attacker.move_slot[move_index].name)
dialogue_text.text = (attacker.name + " is attacking")
dialogue_ani.play("TextScroll")
target.take_damage(attacker.move_slot[move_index],attacker)
yield(get_tree().create_timer(2), "timeout")
_update_view()
if attacker.crit:
attacker.crit = false # Where I turn it off
print(attacker.crit)
yield(critical_hit(attacker),"completed")
else:
yield(attack(attacker, target), "completed")
func attack(attacker, target):
var random_move = randi() % 3 + 1
print(attacker.move_slot[move_index].name)
dialogue_text.text = (attacker.name + " is attacking")
dialogue_ani.play("TextScroll")
target.take_damage(attacker.move_slot[random_move],attacker) # Calls the function to take damage
yield(get_tree().create_timer(2), "timeout") #Wait for 2 seconds
_update_view()
if attacker.crit:
attacker.crit = false # Where I turn it off
print(attacker.crit)
yield(critical_hit(attacker),"completed")
these two functions is how I check if the player is attacking I need to do this because I want the player to use a selected move, if isnt player then play enemy attack
and this is my monster script, where I detect if a critical hit happens, I should say this the monster script is a resource and is separate from the other script, where player, enemy and critical hit function is all in one script.
func take_damage(move,attacker):
randomize()
var critical = 1
#var critical_chance = randi() % 100 + 1
var critical_chance = 5
if critical_chance <= 99.25:
crit = true
critical = 2
var type : float = Get_effectiveness(move.type,type_1) * Get_effectiveness(move.type,type_2)
var modifier : float = rand_range(0.85,1.0) * type * critical
var a : float = (2.0 * attacker.level / 5.0 + 2.0)
var b : float = (a * attacker.attack * move.power / defence) / 50.0
var c : float = (b + 2.0) * modifier
var damage = int(c)
current_health -= damage
print(str(attacker.name) + " = " + str(damage))
#print(a)
#print(b)
Currently I have it pretty much be true every time the player or enemy attacks so it should call/ show the critical hit function, I turn the crit bool to false in the first few functions so it should only happen once
This is the function that adds text to the screen it also prints it to tell me its working but it doesnt print it, if its the first attacking monster, am I making a noobie mistake here?
func critical_hit(attacker):
dialogue_text.text = (attacker.name + " has landed a critical hit!")
dialogue_ani.play("TextScroll")
print(attacker.name + " has landed a critical hit!")
yield(get_tree().create_timer(3), "timeout")

Priority when 2 keys are pressed at the same time - script for a game

Basically, I want it so that when I have 2 keys pressed together (both A and D, specifically), the last key pressed should have priority, and the key before that should be "suppressed" (no input).
For example: in a game, when you press A, your character moves to the left, and when you press D, he moves to the right.
Pressing those 2 keys together makes the character stop.
Now the thing here is that I don't want the character to stop, I want him to continue to move, based on the last key I pressed, even though I'm holding 2 keys at the same time.
I thought this was going to be a trivial task but I actually got a little overwhelmed after trying to learn how to implement this (I'm a noob, sorry :C ), so I came here looking for some help on how to do this on AHK or any easy to compile scripting language that directly changes the input of a key. I'm not trying to modify or create a game, so a script that remaps those keys is enough!
Autohotkey example, following your "A and D, specifically" question:
for k,v in StrSplit("ad")
Hotkey, % "~$" v,Silveirous
Silveirous:
t:=SubStr(A_PriorHotkey,3)
if GetKeyState(t) and (A_ThisHotkey!=A_PriorHotkey)
Send {%t% up}
return
Documentation:
for k,v in, StrSplit(), Hotkey,,,, "~$", SubStr(), A_Prior/ThisHotkey, if, GetKeyState(), t:=... and ... !=, Send {%t% up}
Edit:
Another solution, made to be working as explained in OP's edit/comment:
#If GetKeyState("d","p")
~a::Send {d up}
~a up::Send {d down}
#If GetKeyState("a","p")
~d::Send {a up}
~d up::Send {a down}
#If
Make sure to mind the difference between #If and if (expression) usage cases.
I'm too late but this could help someone in future :)
Basically you need a variable to keep track of which direction the character faced first and act according to that. A code example could be:
let currentDir = 0;
let maxSpeed = (deltaTime * someConstant);
if (IsKeyDown(KEY_RIGHT) && IsKeyDown(KEY_LEFT))
{
if (currentDir == 1)
speed.x = -maxSpeed;
else if (currentDir == -1)
speed.x = maxSpeed;
}
else if (IsKeyDown(KEY_LEFT))
{
currentDir = -1;
speed.x = -maxSpeed;
}
else if (IsKeyDown(KEY_RIGHT))
{
currentDir = 1;
speed.x = maxSpeed;
}
else
{
speed.x = 0.0f;
currentDir = 0;
}
//And at last player's position would change every frame
player.x += speed.x;
Then when you press left while pressing right the character moves left without stopping and vice versa :)

Count the time from my last arrow key press

I was explained before on the forum how to program an autohotkey script to pause the script execution until alpha-numerical character has been entered, by using an input command:
Input, L, V L1 T2 ;wait until you start typing a letter and then proceed after the T2 pause
If (ErrorLevel = "Timeout") {
Send, {Tab 5}
Send, {Enter}
Return
}
I wonder if I can use Input or some other autohotkey command to do the same for non-alphanumerical keys, like arrow keys, or even key combinations. For example, I'd like for the script to count the time from my last arrow key press when I'm selecting an item from a drop-down list, and when the pre-set time threshold is passed to continue with the execution of the script.
EDIT:
Thanks to Blauhirn, the script works now the up and down keys are added :) (as long as the first key is typed in within the pre-set time period of two seconds in this example, notepad will be launched as soon as a pause of one second in typing is made)
!^+u::
Input, L, V L1 T2, {up} {down}
If (ErrorLevel = "Timeout") {
Send, {Esc}
Return
}
Loop { ;wait until you haven't typed an arrow key for 1seconds
Input, L, V L1 T1, {up} {down}
If (ErrorLevel = "Timeout")
Break
}
Run, %windir%\system32\notepad.exe
Return
If you state some EndKeys, the input will also terminate and ErrorLevel will be EndKey:name, thus not "Timeout".
Input, L, V L1 T2, {up}{down} ;wait until you start typing a letter -OR UP ARROW OR DOWN ARROW - and then proceed after the T2 pause
If (ErrorLevel = "Timeout") {
Send, {Tab 5}
Send, {Enter}
Return
}

Build a javascript sliding puzzle

I am attempting to build a game that follows the same mechanic as Dragon's Tail featured at the following link http://bit.ly/1CR0iha. I have built a very basic version of level one working using mouse clicks with one open space. I really want it to move on pressmove so that I can drag the pieces to move them rather than on click which will help when there are more than one open space as on level two.
How to confine the movement of the pieces so that they can ONLY move into the open space? My initial though was to place all the pieces into a grid and check for collisions between the various pieces on pressmove and only allow a move if there is no collision.
After some coding I need a sanity check because I am now second guessing my decision. I am asking for on a high level sanity check on my method any insights are most welcome ;);
Once I have set my x and y on mousedown I them do the following on pressmove. I am not limiting my direction which is what I am trying to achieve.
pressMove = function(event){
var pt = this.globalToLocal(event.stageX, event.stageY);
if(pt.x > this.startPosX){
this.dragDirection = 'right';
}
if(pt.x < this.startPosX){
this.dragDirection = 'left';
}
if(pt.y < this.startPosY){
this.dragDirection = 'up';
}
if(pt.y > this.startPosY){
this.dragDirection = 'down';
}
movePiece(event);
}
Moving the piece
movePiece = function(event){
var obj = event.target;
var pt = this.globalToLocal(event.stageX, event.stageY);
switch(this.dragDirection){
case 'up':
obj.y = pt.y;
break;
case 'down':
obj.y = pt.y;
break;
case 'left':
obj.x = pt.x;
break;
case 'right':
obj.x = pt.x;
break;
};
}
you don't need sofisticated collision detection - all you need to know is which are the possible moves (up, down, right, left) allowed for a clicked piece.
you can do this by having a 2d field representing blocked spaces 1 and free spaces 0 like so
A B C D
X 1 0 1 1
Y 1 1 1 1
Z 1 1 1 1
say you click the piece (Y,B) you can see by checking its four neighbouring entries that only the move up is available, similarly for XA and XC. for all other pieces there are no free spaces and thus no possible moves. after moving a piece, make sure its again in a grid position and update the 2d field. i.e. after moving YB up the field should look like this:
A B C D
X 1 1 1 1
Y 1 0 1 1
Z 1 1 1 1
you can make boundary handling easier by surrounding your actual playfield with blocked spaces
Edit: say you only move up/down and left/right. Every move starts at the center of a piece. Around the center there's a deadzone where it's not clear (yet) which direction the move will take. Then your code might look like this:
startDrag(x, y) {
// remember clicked piece p
p <- ...
// remember center positions for p (cX, cY)
(cX, cy) <- ...
// remember offset of cursor to center (oX, oY)
(oX, oY) <- (x - cX, y - cY)
}
continueDrag(x, y) {
// select move direction
if distance between (cX, cY) and (x - oX, y - oY) is within the deadzone
select move direction (up, down, left, right) with least projection error
else
select last move direction
end
// get constrained move direction
switch selected move direction
case up: perform move to (cX, y - oY)
case down: perform move to (cX, y - oY)
case left: perform move to (x - oX, cY)
case right: perform move to (y - oX, cY)
end
}
you can see all of this in action (and a bit more robust) here: http://js.do/code/sliding-puzzle

Make second monitor go fullscreen with AHK

I have this Autohotkeys script and I need help on it. By pressing win+b the window will move the the other monitor, in this case monitor 2. I would like for whenever it goes to monitor 2 to also throw it in fullscreen using the keyboard shortcut f11, then when sent back over to monitor 1 take it out of fullscreen, then throw it over. Is this possible? This is what I have now.
SysGet, Mon1, Monitor, 1
SysGet, Mon2, Monitor, 2
#b::
winget,windowtomove,id,A ;move active window
gosub windowmove
return
windowmove:
if not mon2left
return
wingetpos,x1,y1,w1,h1,ahk_id %windowtomove%
winget,winstate,minmax,ahk_id %windowtomove%
m1:=(x1+w1/2>mon1left) and (x1+w1/2<mon1right) and (y1+h1/2>mon1top) and (y1+h1/2<mon1bottom) ? 1:2 ;works out if centre of window is on monitor 1 (m1=1) or monitor 2 (m1=2)
m2:=m1=1 ? 2:1 ;m2 is the monitor the window will be moved to
ratiox:=abs(mon%m1%right-mon%m1%left)-w1<5 ? 0:abs((x1-mon%m1%left)/(abs(mon%m1%right-mon%m1%left)-w1)) ;where the window fits on x axis
ratioy:=abs(mon%m1%bottom-mon%m1%top)-h1<5 ? 0:abs((y1-mon%m1%top)/(abs(mon%m1%bottom-mon%m1%top)-h1)) ;where the window fits on y axis
x2:=mon%m2%left+ratiox*(abs(mon%m2%right-mon%m2%left)-w1) ;where the window will fit on x axis in normal situation
y2:=mon%m2%top+ratioy*(abs(mon%m2%bottom-mon%m2%top)-h1)
w2:=w1
h2:=h1 ;width and height will stay the same when moving unless reason not to lower in script
if abs(mon%m1%right-mon%m1%left)-w1<5 or abs(mon%m2%right-mon%m2%left-w1)<5 ;if x axis takes up whole axis OR won't fit on new screen
{
x2:=mon%m2%left
w2:=abs(mon%m2%right-mon%m2%left)
}
if abs(mon%m1%bottom-mon%m1%top)-h1<5 or abs(mon%m2%bottom-mon%m2%top)-h1<5
{
y2:=mon%m2%top
h2:=abs(mon%m2%bottom-mon%m2%top)
}
if winstate ;move maximized window
{
winrestore,ahk_id %windowtomove%
winmove,ahk_id %windowtomove%,,mon%m2%left,mon%m2%top
winmaximize,ahk_id %windowtomove%
}
else
{
if (x1<mon%m1%left)
x2:=mon%m2%left ;adjustments for windows that are not fully on the initial monitor (m1)
if (x1+w1>mon%m1%right)
x2:=mon%m2%right-w2
if (y1<mon%m1%top)
y2:=mon%m2%top
if (y1+h1>mon%m1%bottom)
y2:=mon%m2%bottom-h2
winmove,ahk_id %windowtomove%,,x2,y2,w2,h2 ;move non-maximized window
}
return
Thanks for any of your help!
It is indeed possible, here you go:
sysGet, d2, monitor, 2
#ifWinActive ahk_class Chrome_WidgetWin_1
#b::
winGetPos, cx, cy, a
winGet, style, style
if !(style & 0xC00000)
send {f11}
send {blind}+#{right}
if !(((cx >= d2Left && cx <= d2Right) or (cx >= d2Right && cx <= d2Left)) and ((cy >= d2Top && cy <= d2Bottom) or (cy >= d2Bottom && cy <= d2Top)))
send {f11}
return