Ask coding questions

← Back to all posts
How do I bind a key to run a section of code?
Jrb12

So I've been working on a project, and wondering if there was a way that I could bind a key so that whenever you press that key (i.e., 7 or 9) that it would run a certain section of code. Is that possible?

Answered by InvisibleOne [earned 5 cycles]
View Answer
Voters
Jrb12
Comments
hotnewtop
InvisibleOne

Yeah, it looks like your using getch, so you would need to do something like this:

Jrb12

Thanks! So what code do I put in? Just anything I want it to execute? @InvisibleOne

InvisibleOne

Yeah, a function is just a block of code, and then you can call that function and execute that code. @Jrb12

InvisibleOne

And by looking at your code, I can see that you've got most of it right, but on line 19 it should be: if debut == "BossFight":

Jrb12

@InvisibleOne K, thanks! Will be experimenting a bit

InvisibleOne

np, let me know if you have anything I might be able to help you with. @Jrb12