So I tried to automate running in a game, where the map is huge, and I have to run miles. I wanted to toggle on the hotkey (Ctrl+Shift+A or something else) press the running (in the game, I can run with w).
I tried code, like:
Pause On
Loop
Send w
+^a::Pause
(it can press the w, but it can't release) and like this:
+^a::
toggle := !toggle
while toggle
Send {w down}
(same problem).
It's just my problem, or these codes are wrong?
I have a (at least i think) much simpler solution :)
#NoTrayIcon
ScrollLock::
Input, Key, ,{Enter}
Send, {%Key% Down}
return
You press ScrollLock (which I doubt you use for anything else, otherwise set it to a free key), and then enter the name of button to be held down.
If you want to hold down a single character, you just write it in.
For other keys you can find the names here: http://www.autohotkey.com/docs/KeyList.htm
Mouse: LButton for left, RButton for right and MButton for middle
You end the input with the Enter key, and after that the program will hold down the entered key.
If you want to "lift up" the key, just simply press it once, and it will be held down no more. :)
ps.:I have #NoTrayIcon, because I'm running it permanently in the background, but if you wanted to be able to exit then simply add something like this:
F12::
ExitApp
return
This is my stock function. I usualy map it to ^W or Q. Pressing w or s will cancel it. Easy peasy.
HoldW(){
SendInput {w up}{w down}
Loop
{
Sleep 100
GetKeyState state, w
if state = u
return
If GetKeyState("s")
{
SendInput {w up}
return
}
}
}
+^vk41:: ; shift+ctrl+a
SetTimer, % "SomeLable", % (bToggle:=!bToggle) ? 25:"Off"
KeyWait, % "vk41"
Return
SomeLable:
SendInput, % "{vk57}" ; w
Return
A silly noob example where F10 is the toggle hotkey, and the up/down state is a variable. The variable needs to be pre-declared to give the initial value.
To be honest I expected an error message, but it seemed to run fine.
keystate=down
F10::
Send {w %keystate%}
if keystate = down
SetEnv, keystate, up
else if keystate = up
SetEnv, keystate, down
return
Toggle := 1
Q::Send, % Toggle = 1 ? ( "0", Toggle := 0 ) : ( "9", Toggle := 1 )
Change Q to your preferred hotkey, and change "0" and "9" to the keys you want to toggle through. Make sure to set your abilities or weapons to the keys you replace in "0" and "9".
So, lets say I have a primary and secondary weapon. I bind them in game to 9 and 0.
I press Q to cycle between them for fast weapon switching. Or w/e else you want.
Related
I have a problem with a pygame window disappearing immediately after it has been opened I know this can be resolved with a loop around the pygame.quit but i cant be able to solve it.
enter code he enter codeimport sys
import pygame
pygame.init()
quit = 1
if(quit == 2):
pygame.quit
if (quit == 1):
wind = pygame.display.set_mode((600,600))
width = 300
height = 300
x = 300
y = 300
vel = 1re
You window closes immediately, because your application is immediately terminated. You need an application loop. The typical PyGame application loop has to:
limit the frames per second to limit CPU usage with pygame.time.Clock.tick
handle the events by calling either pygame.event.pump() or pygame.event.get().
update the game states and positions of objects dependent on the input events and time (respectively frames)
clear the entire display or draw the background
draw the entire scene (blit all the objects)
update the display by calling either pygame.display.update() or pygame.display.flip()
e.g.:
import pygame
pygame.init()
window = pygame.display.set_mode((600, 600))
clock = pygame.time.Clock()
# main application loop
run = True
while run:
# limit frames per second
clock.tick(100)
# event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# clear the display
window.fill(0)
# draw the scene
pygame.draw.circle(window, (255, 0, 0), (250, 250), 100)
# update the display
pygame.display.flip()
pygame.quit()
exit()
I think it quits because the code has finished executing, and I don't see a loop in your code currently...
Maybe something like:
# Initialise your pygame stuff
isRunning = true
while isRunning:
# Respond to events from pygame
if certainCondition:
isRunning = false
pygame.quit()
I am trying to make an application for users to show their actions on timeLine.
My timeline library named StepProgressView hasn't delegate or dataSource. So I can't change text color in iteration with my keys.
There is a titleLabel and subtitleLabel in my timeLine library. If you want how it works you can check the library in this link
I have title and subTitle array on my project. When I add the titles in my array it gives me timeLine with array items.
I want to change titleLabel text color.
This is my dictionary output when i print it.
[17: "17 Kind of long rambling explanation that no one reads in reality",
14: "14 Kind of long rambling explanation that no one reads in reality",
20: "20 Kind of long rambling explanation that no one reads in reality"
I want to use if else statement for colors. If dict value is 17 text color should be red or something.
But when I iterate it fills with last color of key value. This is my problem. I hope its clear.
for (key, _) in self.stepDetails {
progressView.pastTextColor = getColor(key: key)
}
func getColor(key: Int) -> UIColor {
switch key {
case 0...key:
return .red
case key ... key + 10:
return .blue
default:
return .gray
}
}
It always gives last color because it's in iteration so
What is the best approach in this case ?
Thank you !
I am creating a game that when your health goes below 0, on a keydown it prints in a div:
"Game_over_:(_click_to_continue" letter by letter. I was getting a bug where the letters would print out multiple times like ggggaaammmeee ooovvveerr.
I set up a conditional statement where if the state gameOver is 0 and after a keydown event, then it activates the setInterval, else it does not. That solved the problem to some extent, however, the state sometimes changes a second late, and after setting up console.log(this.state.gameOver), it sometimes prints 0 twice before this.state.gameOver actually changes to 1. Other times it works just fine.
if (this.state.gameOver===0){
console.log(this.state.gameOver)
var s1="Game_Over\n:(\nClick_to_continue..."
var v1 =0
var b = document.getElementById("redButton")
var arr1 = setInterval(function(){
if(v1===0){b.innerText=""};b.innerText= b.innerText+s1[v1];v1+=1;
if(v1==s1.length){clearInterval(arr1)}}, 100)
this.setState({gameOver:1})
}
It's still sometimes printing Ggaammee Ovveerr.
So all I had to do was set up a conditional statement that depends on whether a variable is true or false. Once the setInterval function is triggered, the variable changes to false so that more keydowns wont cause multiple calls to setInterval.
var check;
if (check!==false){
check=false;
var arr1 = setInterval(function(){
if(v1===0){b.innerText=""};
b.innerText= b.innerText+s1[v1];v1+=1;
if(v1==s1.length){clearInterval(arr1)}}, 100)}
Once I click the screen with the mouse:
check=true;
I know I can do something like this:
<div class="contentView"
ng-keypress="phs.keyEnter($event)">
keyEnter = ($event): void => {
var a = $event;
var b = $event.keyCode;
}
But is there a way that I can detect if both the Command or Option key is pressed at the same time as the Return key?
The $event indicates some keys that were simultaneously pressed (such as ctrl, alt...).
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent.
Not sure about cmd, but check it out.
You can also combine ngKeypress & ngKeyup to check when cmd key was pressed and return key was released and determine when those events overlap.
I have a beat em up game and a 'punch' sound is played on a timer if an enemy collides with my character as shown below:
local function hitSound()
local hsound = math.random(#sfx.hit)
audio.play(sfx.hit[hsound])
end
--------------------------------------------------CHARACTER COLLISION---------------
local function guyCollision(self, event)
if event.other.type == "enemy1"then
if event.phase == "began" then
hitTimer = timer.performWithDelay(500,hitSound,0)
event.other:setSequence("punch")
event.other:play()
end
if event.phase == "ended" then
timer.pause(hitTimer)
end
This works fine when my character is taking down just one enemy at a time but if there are more than one spawned enemy (which there usually is) fighting my character when i kill them the punching sound remains.
Also when i call audio.fadeout() when my character dies the punch sounds don't fade out with the other sounds/music :s
Someone suggested to me to assign the timer to the specific enemy in question using its index in its table but im unsure of how to do this... is this the best way? I just don't know how to get that enemys current index.. any help much appreciated!
Heres my enemy spawn code:
local spawnTable2 = {}
local function spawnEnemy()
enemy1 = display.newSprite( group, sheetE, sequenceData2 )
enemy1.x=math.random(100,1300)
enemy1.y=math.random(360,760)
enemy1.gravityScale = 0
enemy1:play()
enemy1.type="coin"
enemy1.objTable = spawnTable2
enemy1.index = #enemy1.objTable + 1
enemy1.myName = "enemy" .. enemy1.index
physics.addBody( enemy1, "kinematic",{ density = 1.0, friction = 0.3, bounce = 0.2 })
enemy1.isFixedRotation = true
enemy1.type = "enemy1"
enemy1.enterFrame = moveEnemy
Runtime:addEventListener("enterFrame",enemy1)
enemy1.objTable[enemy1.index] = enemy1
return enemy1
end
I think your problem is that your hitTimer variable is probably being overwritten and you can only cancel the last one. You could probably do: self.hitTimer to get around it.
Rob