Jump to content


Photo

Multiple Key Press


  • Please log in to reply
22 replies to this topic

#1 06jamhob

06jamhob

    GMC Member

  • New Member
  • 664 posts

Posted 21 December 2008 - 11:22 AM

i need 2 no how 2 2 set key press or key board as pressing 2 keys at once 2 make the event happen
btw i am using drag and drop im a noob

Edited by 06jamhob, 21 December 2008 - 11:24 AM.

  • 0

#2 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2398 posts
  • Version:GM7

Posted 21 December 2008 - 11:30 AM

I don't think you can do this w/ D & D :D I know you can do it with code, though.
  • 0

#3 06jamhob

06jamhob

    GMC Member

  • New Member
  • 664 posts

Posted 21 December 2008 - 11:32 AM

if u told me the code id put it in

Edited by 06jamhob, 21 December 2008 - 11:33 AM.

  • 0

#4 tommygame

tommygame

    GMC Member

  • New Member
  • 809 posts

Posted 21 December 2008 - 11:36 AM

well it would be hard without code so here is the code ~ (that i think would work)

create event

global.multikeypress=false  //creates a controlling variable, accsesible by all objects




step event:

if keyboard_check_pressed(*) global.multikeypress+=1 // check for 1st key (change* to your key)
 if keybourd_check_pressed(*2)global.multikeypress+=1 //checks for 2nd key (change*2 to your key)

if global.multikeypress=2 ....... //checks if they have both been pressed
else
global.multikeypress=false //if not sets it to false

im nt sure on some of the code, as i cant test as on hols.


im sure someone will correct it if its wrong.

tommygame

[/code]

Edited by tommygame, 21 December 2008 - 11:36 AM.

  • 0

#5 06jamhob

06jamhob

    GMC Member

  • New Member
  • 664 posts

Posted 21 December 2008 - 11:37 AM

thx but 1 thing
how do i select which 2 keys i want 2 be pressed?
sorry didnt read it all get it now

Edited by 06jamhob, 21 December 2008 - 11:39 AM.

  • 0

#6 06jamhob

06jamhob

    GMC Member

  • New Member
  • 664 posts

Posted 21 December 2008 - 11:48 AM

COMPILATION ERROR in code action
Error in code at line 1:
if keyboard_check_pressed(*) global.multikeypress+=1 // check for 1st key (space)

at position 27: Unexpected symbol in expression.

waht is wrong? it keeps coming up with this error
  • 0

#7 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2398 posts
  • Version:GM7

Posted 21 December 2008 - 11:50 AM

COMPILATION ERROR in code action
Error in code at line 1:
if keyboard_check_pressed(*) global.multikeypress+=1 // check for 1st key (space)

at position 27: Unexpected symbol in expression.

waht is wrong? it keeps coming up with this error


everything after // is just a comment (code that doesn't do anything) the comment he's saying is he wants that first part to be

if keyboard_check_pressed(space) global.multikeypress+=1 //see the * is now space. This is just a comment

EDIT: Actually now that I know that code there's a simpler way using D and D and code.
Have one key event (the one that is probably going to be held down while the other is pressed)
In that put the code:

a=keyboard_check_pressed(put the OTHER key here);
if (a = true) {Run the code you want to be done here};


I'll need for you to tell me what you want to happen if both are pressed here so I know what to put between {}

Edited by greep, 21 December 2008 - 12:00 PM.

  • 0

#8 06jamhob

06jamhob

    GMC Member

  • New Member
  • 664 posts

Posted 21 December 2008 - 12:03 PM

i want it 2 change 2 a sprite called (PUNCH left)
  • 0

#9 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2398 posts
  • Version:GM7

Posted 21 December 2008 - 12:08 PM

i want it 2 change 2 a sprite called (PUNCH left)


alright, so...

a=keyboard_check_pressed(put the OTHER key here);
if (a = true) {sprite_index=PUNCH_left};

However,for this tor work, you need to rename "PUNCH left" to "PUNCH_left" (spaces don't work in code, and neither do parantheses, commas, and a bunch of other things.).

Edited by greep, 21 December 2008 - 12:15 PM.

  • 0

#10 Force

Force

    GMC Member

  • New Member
  • 20 posts

Posted 21 December 2008 - 12:14 PM

GOD! Why are you using the most complicated way!

if keyboard_check_pressed(vk_right) && keyboard_check_pressed(vk_up)
{game_end()}


  • 0

#11 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2398 posts
  • Version:GM7

Posted 21 December 2008 - 12:16 PM

GOD! Why are you using the most complicated way!

if keyboard_check_pressed(vk_right) && keyboard_check_pressed(vk_up)
{game_end()}


hey, no trolling :P That would be funny if he actually did that tho :D
  • 0

#12 nick3401

nick3401

    GMC Member

  • New Member
  • 146 posts

Posted 21 December 2008 - 12:35 PM

That is however the simplest way to do it.

you can use ord('A') to use a letter key pressed rather then just the vk_arrows. replace A with the letter of your choice.
  • 0

#13 cephei

cephei

    GMC Member

  • GMC Member
  • 801 posts

Posted 21 December 2008 - 12:44 PM

You can stick to D&D:
:D Event: Key Press <Right>
:P If Expression: "keyboard_check(vk_up)"
...do something...


and by the way:

GOD! Why are you using the most complicated way!

if keyboard_check_pressed(vk_right) && keyboard_check_pressed(vk_up)
{game_end()}


that wont work since the "_pressed" is only true in the step after the button was actually pressed and normally, you wont hit both keys in the same 1/30 second ^^

If you want "hold <up> and then press <right>"-combo use

if(keyboard_check_pressed(vk_right) && keyboard_check(vk_up)){game_end()}

Edited by cephei, 21 December 2008 - 12:48 PM.

  • 0

#14 Olly532

Olly532

    GMC Member

  • New Member
  • 17 posts

Posted 21 December 2008 - 05:45 PM

Hi i have the same problem but im using wasd keys to move and the above methord doesnt work

please help!!!

Im using d+d pro gm 7
  • 0

#15 06jamhob

06jamhob

    GMC Member

  • New Member
  • 664 posts

Posted 21 December 2008 - 05:45 PM

[quote name='cephei' date='Dec 21 2008, 12:47 PM' post='2985893']
You can stick to D&D:
;) Event: Key Press <Right>
;) If Expression: "keyboard_check(vk_up)"
...do something...


can u make the above work for (wasd)
  • 0

#16 Hardcore.

Hardcore.

    GMC Member

  • New Member
  • 60 posts

Posted 21 December 2008 - 05:47 PM

if keyboard_check(vk_right) && keyboard_check(vk_left)
{game_end()}
  • 0

#17 06jamhob

06jamhob

    GMC Member

  • New Member
  • 664 posts

Posted 21 December 2008 - 06:43 PM

ha ha ha ur funny
  • 0

#18 jomo24

jomo24

    GMC Member

  • New Member
  • 252 posts

Posted 21 December 2008 - 07:13 PM

You can stick to D&D:
;) Event: Key Press <Right>
;) If Expression: "keyboard_check(vk_up)"

...do something...


can u make the above work for (wasd)

Instead of VK Up.. use..



If expression: keyboard_check(ord('*')

Replace the asterik with any letter of the alphabet..
  • 0

#19 T. Westendorp

T. Westendorp

    GMC Member

  • New Member
  • 1270 posts
  • Version:Unknown

Posted 21 December 2008 - 07:15 PM

But make sure it is capitalized like this: ord('A') because ord('a') won't work.



T
  • 0

#20 tommygame

tommygame

    GMC Member

  • New Member
  • 809 posts

Posted 25 December 2008 - 11:51 AM

do you understand yet??

to be fair its not to hard to understand.... also i did clearly say chand the * to your choosen key so:

keyboard_check_pressed(*) would become keyboard_check_pressed(ord('a')

also i forgot to mention if you use variabls to track the keys you will want some point it reset to 0.

so :


//what happens after the keys are preesed....

global.multikeypress=0

.

i think my way would work you just need to understand it alos you could add timing so if its not pressed after 5 steps/secs then its reset back to 0.
but i cant tell you hw as on hols.

peace
  • 0

#21 kupiakos

kupiakos

    Ninjas beat pirates

  • New Member
  • 369 posts

Posted 25 December 2008 - 02:53 PM

In the step event code put this:
if (keyboard_check(ord("W")) && keyboard_check(ord("D"))) then sprite_index=PUNCH_left

Like Greep said, the sprite PUNCH left needs to be changed to PUNCH_left

If you do not want WASD movement, simply change ord("W") to vk_up, and ord("D") to vk_right.

Hope the code works for you! You don't even have to add an event!
  • 0

#22 thendrluca

thendrluca

    GMC Member

  • New Member
  • 11 posts
  • Version:None

Posted 04 January 2014 - 11:38 AM

i need 2 no how 2 2 set key press or key board as pressing 2 keys at once 2 make the event happen
btw i am using drag and drop im a noob

 

i made this way

when i hit left Ctrl and R the game is restarting

// Create Event
lctrl = false;
alt = false;
// ... and so on for all keys you use

// Step Event
// setting if key is pressed or not
if keyboard_check_pressed(vk_lcontrol)
    lctrl = true;
if keyboard_check_released(vk_lcontrol)
    lctrl = false;
if keyboard_check_pressed(vk_alt)
    alt = true;
if keyboard_check_released(vk_alt)
    alt = false;
// ... make this for other keys

// if left cltr is pressed
if lctrl
{
    // if R is pressed
    if keyboard_check_pressed(ord("R"))
        game_restart();
    // ... and so on for all leftCtrl + KEY
}
// if alt is pressed
if alt
{
    // ... do like on left ctrl
}

Edited by thendrluca, 04 January 2014 - 11:52 AM.

  • 0

#23 SuperGamersGames

SuperGamersGames

    GMC Member

  • New Member
  • 11 posts
  • Version:GM:Studio

Posted 04 January 2014 - 05:27 PM

If You Need Help I'll Give You Help I Had Trouble With This And I Found Out Put This In Code

if keyboard_check(KEY) && keyboard_check(KEY)
then //ACTION

Check Out My Channel SuperGamersGames


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users