Keyboard presses

Is there a way to know whether a keyboard key is being pressed. Something like key.state==BEGAN or MOVING?

You could use a keyboard buffer to detect if someone is pressing a certain key, though this is a bad way to go if you want to use the keyboard for something else.

@Saurabh You didn’t say what you wanted to do if you detected a key press. Here is a way of knowing if a key was pressed.


function setup()
    kb=""
    showKeyboard()
end

function draw()
    background(40,40,50)
    if kb~="" then
        whatEver()    -- perform whatever if a key was pressed
        kb=""         -- set kb back to ""
    end
end
    
function keyboard(k)
    kb=k 
end

function whatEver()
    print(kb)
end

what I wanted is a way to know if the persons finger is on the key or he has raised his finger from the key. similar to he is touching the screen or stopped touching the screen

@dave1707 He wants to know specifically when a key has started being pressed and ended, so, say, you could have an event trigger while the user is pressing on the key, not just when they start pressing it, and keyboard(key) is called that one time.

I also want to know if this is possible, because then we could use the keyboard as controls, like Minecraft on a desktop.

Man again. @SkyTheCoder http://www.genderchecker.com/

But would we really want to use the keyboard? I mean, the Ipad keyboard is really annoying, IMHO.

@Saurabh I was playing around with the keyboard and what I came up with is: if you touch a key and move your finger to another key, nothing is returned. no key value is returned when a key is first touched. a key value is returned when you lift your finger from a key provided you didn’t move from that key. What are you doing that you need to know when the keyboard is touched or your finger is being lifted from the keyboard.

I was kind of using the external keyboard. And was making a platform game. So it would be like a desktop experience.

@SkyTheCoder I’m not familiar with Minecraft so I don’t know how the keyboard is used. I don’t see what the problem is by creating the keys( buttons) that you need. Then you have full control over them using the function touched.

@Saurabh So you want to use the external keyboard so you have the full screen of the iPad for the graphics without cluttering it up with keys(buttons).

@dave1707 that’s right but keeping the ipad in the case stand and using the keyboard will make it something like a laptop. Unlike keys on the screen which will one block screen space and two not give that inclined screen experience. So if it were just possible.

@dave1707 Yeah, you could program your own, but the soft keyboard is built-in and I’m lazy. :stuck_out_tongue:

Also… how could you possibly not be familiar with Minecraft??? It’s got over eleven million sales and counting! By the second!

@Saurabh I don’t have an external keyboard to play with, but if it works like the iPad keyboard it isn’t going to work how you want. @SkyTheCoder I’m not into games. I lose interest in them too fast so I stopped playing/buying them long ago.

@dave1707 I need to stop spamming this discussion with unrelated comments, but seriously, Minecraft is not something you’ll get bored with.

Yeah maybe I’ll have to think of something else which can replicate its behavior as close as possible.