Several keys pressed in the same time (C#, .NETCF, SP2003)

G

Guest

Hi,

I'm programming in C# on a Smartphone 2003, and I have problem because I
would like to be able to catch several key in the same time, for basic
example in a mere game, to be able to press acceleration button and to turn
without releasing acceleration...

I tried in OnKeyPress event, does work, I tried also in a loop, using
GetAsyncKeyState but it seems to never work...

I would like to know if it's a hardware limit or if I did something wrong...
I guess I did something wrong and would be very happy to have a tip to help ;)

Thank you in advance
 
P

Paul G. Tobey [eMVP]

What keys, specifically, are you talking about? You should be able to
detect things like the Alt, Control, and Shift keys in combination with
basically anything. Regular keys, however, you might not be able to detect
in combination with one another ("J" and "8", say).

Paul T.
 
G

Guest

Shift, Alt, Control ? on a Smartphone ? where are these keys ? :p

No but I just did additionnal test and it seems it's an hardware blocking :S
I did that in a timer loop :

short[] keys = new short[256];

for (int i = 0; i < keys.Length; i++)
keys = GetAsyncKeyState(i);

if (keys[48] != 0) // this is 0 phone key
// jump
if (keys[37] != 0) // this is left pad-key
// turn left
if (keys[39] != 0) // this is right pad-key
// turn right

but as long as I press Right (holding the key), I can press jump (0 phone
key) but it's always ignored, and if I press Left (still holding the key), so
as soon as I press the jump (0 phone key) everything freeze... then I release
the 0 phone key and it goes on to walk left...

Someone could bring me lights about that please ?
Thanks
 
P

Paul G. Tobey [eMVP]

Exactly. It's the same effect, just not the same key names. There are not
separate inputs for each key on most keypads. The pad is arranged in rows
and columns. A signal is sent out, periodically, on each row and then the
columns are polled, looking for the signals. When a signal is seen, the key
in the corresponding row and column position is 'down'. So, keys in
different columns can be seen as down at the same time, but keys in the same
column can't be distinguished.

Since, on a well-designed keypad, the Control, Shift, and Alt keys are each
in their own columns, they can be detected separately from every other key.
This allows them to be 'seen' properly in combination with all other keys.
However, since the number of columns is finite, you can't detect every key
in combination with every other key. The actual layout, however, is *not*
specified, at least on most devices, so one device might easily not work the
same, with respect to this situation, as *any* other.

I'm not aware of Smart Phones specifying this, so I think you're going to be
stuck unless you can find such a specification or derive one from specific
behavior on specific devices.

Paul T.

sebseb said:
Shift, Alt, Control ? on a Smartphone ? where are these keys ? :p

No but I just did additionnal test and it seems it's an hardware blocking
:S
I did that in a timer loop :

short[] keys = new short[256];

for (int i = 0; i < keys.Length; i++)
keys = GetAsyncKeyState(i);

if (keys[48] != 0) // this is 0 phone key
// jump
if (keys[37] != 0) // this is left pad-key
// turn left
if (keys[39] != 0) // this is right pad-key
// turn right

but as long as I press Right (holding the key), I can press jump (0 phone
key) but it's always ignored, and if I press Left (still holding the key),
so
as soon as I press the jump (0 phone key) everything freeze... then I
release
the 0 phone key and it goes on to walk left...

Someone could bring me lights about that please ?
Thanks


Paul G. Tobey said:
What keys, specifically, are you talking about? You should be able to
detect things like the Alt, Control, and Shift keys in combination with
basically anything. Regular keys, however, you might not be able to
detect
in combination with one another ("J" and "8", say).

Paul T.
 
G

Guest

So... to conclude with less words, and easier... it's a hardware problem that
I can't pass throught by software, right ?

Sorry I'm not english-language native and I didn't understand what you wrote
since you started to talk about Alt, Shift and Control stuffs... but my
problem is that I press on Left and 0 or Right and 0... pad-keys are supposed
to be indepandent, no ? anyway I tried with every key-combination where keys
are on different rows and different columns, but still blocking problem...


Paul G. Tobey said:
Exactly. It's the same effect, just not the same key names. There are not
separate inputs for each key on most keypads. The pad is arranged in rows
and columns. A signal is sent out, periodically, on each row and then the
columns are polled, looking for the signals. When a signal is seen, the key
in the corresponding row and column position is 'down'. So, keys in
different columns can be seen as down at the same time, but keys in the same
column can't be distinguished.

Since, on a well-designed keypad, the Control, Shift, and Alt keys are each
in their own columns, they can be detected separately from every other key.
This allows them to be 'seen' properly in combination with all other keys.
However, since the number of columns is finite, you can't detect every key
in combination with every other key. The actual layout, however, is *not*
specified, at least on most devices, so one device might easily not work the
same, with respect to this situation, as *any* other.

I'm not aware of Smart Phones specifying this, so I think you're going to be
stuck unless you can find such a specification or derive one from specific
behavior on specific devices.

Paul T.

sebseb said:
Shift, Alt, Control ? on a Smartphone ? where are these keys ? :p

No but I just did additionnal test and it seems it's an hardware blocking
:S
I did that in a timer loop :

short[] keys = new short[256];

for (int i = 0; i < keys.Length; i++)
keys = GetAsyncKeyState(i);

if (keys[48] != 0) // this is 0 phone key
// jump
if (keys[37] != 0) // this is left pad-key
// turn left
if (keys[39] != 0) // this is right pad-key
// turn right

but as long as I press Right (holding the key), I can press jump (0 phone
key) but it's always ignored, and if I press Left (still holding the key),
so
as soon as I press the jump (0 phone key) everything freeze... then I
release
the 0 phone key and it goes on to walk left...

Someone could bring me lights about that please ?
Thanks


Paul G. Tobey said:
What keys, specifically, are you talking about? You should be able to
detect things like the Alt, Control, and Shift keys in combination with
basically anything. Regular keys, however, you might not be able to
detect
in combination with one another ("J" and "8", say).

Paul T.

Hi,

I'm programming in C# on a Smartphone 2003, and I have problem because
I
would like to be able to catch several key in the same time, for basic
example in a mere game, to be able to press acceleration button and to
turn
without releasing acceleration...

I tried in OnKeyPress event, does work, I tried also in a loop, using
GetAsyncKeyState but it seems to never work...

I would like to know if it's a hardware limit or if I did something
wrong...
I guess I did something wrong and would be very happy to have a tip to
help ;)

Thank you in advance

 
P

Paul G. Tobey [eMVP]

The *specific* key combination that you are having problems with is probably
a hardware problem, yes. That doesn't mean that, if you have flexibility to
change what key has what meaning you can't do it, though.

As far as I know, there is no independence specified for *any* keys on your
keypad. What I was trying to do was give you enough information about what
is probably going on that you'd be able to search for a specification which
might indicate which keys *are* independent (in different columns, in my
terminology), if any are required to be.

Paul T.

sebseb said:
So... to conclude with less words, and easier... it's a hardware problem
that
I can't pass throught by software, right ?

Sorry I'm not english-language native and I didn't understand what you
wrote
since you started to talk about Alt, Shift and Control stuffs... but my
problem is that I press on Left and 0 or Right and 0... pad-keys are
supposed
to be indepandent, no ? anyway I tried with every key-combination where
keys
are on different rows and different columns, but still blocking problem...


Paul G. Tobey said:
Exactly. It's the same effect, just not the same key names. There are
not
separate inputs for each key on most keypads. The pad is arranged in
rows
and columns. A signal is sent out, periodically, on each row and then
the
columns are polled, looking for the signals. When a signal is seen, the
key
in the corresponding row and column position is 'down'. So, keys in
different columns can be seen as down at the same time, but keys in the
same
column can't be distinguished.

Since, on a well-designed keypad, the Control, Shift, and Alt keys are
each
in their own columns, they can be detected separately from every other
key.
This allows them to be 'seen' properly in combination with all other
keys.
However, since the number of columns is finite, you can't detect every
key
in combination with every other key. The actual layout, however, is
*not*
specified, at least on most devices, so one device might easily not work
the
same, with respect to this situation, as *any* other.

I'm not aware of Smart Phones specifying this, so I think you're going to
be
stuck unless you can find such a specification or derive one from
specific
behavior on specific devices.

Paul T.

sebseb said:
Shift, Alt, Control ? on a Smartphone ? where are these keys ? :p

No but I just did additionnal test and it seems it's an hardware
blocking
:S
I did that in a timer loop :

short[] keys = new short[256];

for (int i = 0; i < keys.Length; i++)
keys = GetAsyncKeyState(i);

if (keys[48] != 0) // this is 0 phone key
// jump
if (keys[37] != 0) // this is left pad-key
// turn left
if (keys[39] != 0) // this is right pad-key
// turn right

but as long as I press Right (holding the key), I can press jump (0
phone
key) but it's always ignored, and if I press Left (still holding the
key),
so
as soon as I press the jump (0 phone key) everything freeze... then I
release
the 0 phone key and it goes on to walk left...

Someone could bring me lights about that please ?
Thanks


:

What keys, specifically, are you talking about? You should be able to
detect things like the Alt, Control, and Shift keys in combination
with
basically anything. Regular keys, however, you might not be able to
detect
in combination with one another ("J" and "8", say).

Paul T.

Hi,

I'm programming in C# on a Smartphone 2003, and I have problem
because
I
would like to be able to catch several key in the same time, for
basic
example in a mere game, to be able to press acceleration button and
to
turn
without releasing acceleration...

I tried in OnKeyPress event, does work, I tried also in a loop,
using
GetAsyncKeyState but it seems to never work...

I would like to know if it's a hardware limit or if I did something
wrong...
I guess I did something wrong and would be very happy to have a tip
to
help ;)

Thank you in advance

 
A

Alex Feinman [MVP]

Try calling
[DllImport("coredll")]

extern static int GetAsyncKeyState(int key);

The key parameter is 0x30-0x39 for buttons from 0 to 9. Non-zero return
value means "pressed".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top