Difference between revisions of "Key input"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>DragoonWraith
(solved it (as much as that is possible), so put it in solutions category, as well as the useful code category)
imported>Gregbert
(Discussion on Article page turned into article.)
 
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
I need to know how (and if) I can handle key input via script. I need to have both swords with ranged attacks and guns with night vision, so I need ether an alternate fire or a mode change button... but Oblivion has nether. Is there anyway key input can be handled? --[[User:Bky|Bky]] 06:40, 30 May 2006 (EDT)
{{Deprecated Article|Key input is now best handled by [[Oblivion Script Extender]].}}


:[[User:DragoonWraith|<font face="Oblivion,Daedric" size=3>D</font>ragoon <font face="Oblivion,Daedric" size=3>W</font>raith]] [[User_talk:DragoonWraith|<font face="Oblivion,Daedric" size=2>TALK</font>]] 12:15, 30 May 2006 (EDT): Nope, there's absolutely no way to detect key presses. Luckily for you (sort of), there wasn't in Morrowind, either, and as you might imagine, this was something a lot of people wanted to do. So, your best bet is to detect something you can detect - Sneaking is easiest. Try something like this:
If you wish to detect a key input without [[OBSE]], then the best way to go about this is to detect what the effect of this key press would be. For example, if you want to detect the pressing of the Ctrl button, then your best best would be to detect Stealth (assuming that the player has Ctrl set to activate Stealth Mode). Using stealth as an example:


<pre>short sneak
<pre>short sneak
short switch
short switch
float timer
float timer
 
/index.php?showtopic=511998&view=findpost
Begin GameMode
Begin GameMode


Line 32: Line 32:
End</pre>
End</pre>


:Basically, "switch" gets increased every time the player hits the Ctrl key (or whatever they have "Sneak" mapped to), and if they hit it four times (I figure no one would hit Sneak four times unless they were deliberately trying to), you activate your code to switch weapon mode or night vision or whatever you're doing.
However, it is impossible (without [[OBSE]]) to detect a key press without the key having an effect. If this is your aim, then [[OBSE]] must be used.
 
==See Also==


[[Category: Useful Code]]
* [[GetKeyPress]]
[[Category: Solutions]]

Latest revision as of 06:21, 26 April 2009


If you wish to detect a key input without OBSE, then the best way to go about this is to detect what the effect of this key press would be. For example, if you want to detect the pressing of the Ctrl button, then your best best would be to detect Stealth (assuming that the player has Ctrl set to activate Stealth Mode). Using stealth as an example:

short sneak
short switch
float timer
/index.php?showtopic=511998&view=findpost
Begin GameMode

  set timer to ( timer + GetSecondsPassed )
  if ( timer > 2 )
    set timer to 0
    set sneak to 0
  elseif ( player.IsSneaking == 1 ) && ( sneak == 0 )
    set switch to ( switch + 1 )
  elseif ( player.IsSneaking == 0 ) && ( sneak == 1 )
    set switch to ( switch + 1 )
  endif

  if ( player.IsSneaking == 1 )
    set sneak to 1
  else
    set sneak to 0
  endif

  if ( switch == 4 )
    set switch to 0
    ;switch weapon mode
  endif

End

However, it is impossible (without OBSE) to detect a key press without the key having an effect. If this is your aim, then OBSE must be used.

See Also[edit | edit source]