Hullo.
Well, I know it was sarcasm when IanM said I should take my day's worth of code and make a plugin out of it, but I did anyways (Only because someone else found a feature would be useful).
Here's the readme so you can see for yourself what's in it.
READ ME.txt
__ ______ _ _ _ _ _ _ _
/ \ | ____| \ \ / / | | | | | \ | | | |
/ /\ \ | |____ \ \ / / | | | | | \ | | | |
/ /__\ \ | ____| \ \/ / | | | | | |\ \| | | |
/ ______ \ | |____ / /\ \ /\ | \__/ | | | \ | | |
/_/ \_\ |______| /_/ \_\ \/ \______/ |_| \__| |_|
________________________________________________________________________
|________________________________________________________________________|
COPYRIGHT (C) 2008 Aex.Uni
Wriiten by Aaron J. Miller
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
INSTALLATION:
Copy "input_plugin.dll" to the Compiler\plugins-user sub-directory of your DBP
installation directory.
Copy "input_plugin.ini" to the Editor\keywords sub-directory of your DBP
installation directory.
EXAMPLES:
Included are 3 examples: Keyboard Input, Mouse Input, and XBox 360 Controller Input.
The names of the files in the examples directory should give away which is which.
Not included is a regular game pad example. None of the normal game pad command
set (denoted by the "gp_" prefix) has been tested in this plugin. However, the
code has (in the past) been tested before and seemed to work fine in it's C++
class bindings.
COMMAND SET NAMES:
Each command set has a 3 character prefix. The first 2 characters are letters and
the 3rd character an underscore. Each command set has an UPDATE function. If you
are using that particular command set then you MUST call the UPDATE function of
that command set once every loop (Or once every time you expect input to change).
The command set prefixes are:
'kb_' for the KEYBOARD command set
'ms_' for the MOUSE command set
'gp_' for the GAME PAD (joy stick) command set
'xb_' for the XBOX 360 GAME PAD (XBox 360 controller) command set
KEYBOARD COMMANDS:
state as dword = kb_getKeyState(index as dword)
This command will retrieve rather or not the key specified in 'index' is
pressed or not. 1 for pressed, 0 for not pressed.
kb_setKeyState index as dword, state as dword
This command will set the key state of the key specified in 'index' which
will cause kb_getKeyState to return the value specified.
kb_flushKeys
This command will clear all key states to zero.
kb_update
This command will update the keyboard input. Call once every time new
input is required (For example, right before a call to SYNC).
MOUSE COMMANDS:
ms_setScreenOn
This command will tell the mouse input device to return where on the DBP
screen the mouse is, instead of where in the window the mouse is. By default
screens are off.
ms_setScreenOff
This command will turn off screens, causing the mouse input device to
return where on the window the mouse is.
x_pos as integer = ms_getX()
This command will return the X position of the mouse.
y_pos as integer = ms_getY()
This command will return the Y position of the mouse.
x_move as integer = ms_getMoveX()
This command will return how many pixels the mouse has moved across the X
axis.
y_move as integer = ms_getMoveY()
This command will return how many pixels the mouse has moved across the Y
axis.
z_move as integer = ms_getMoveZ()
This command will return how much the mouse wheel has scrolled.
state as dword = ms_getState(button as dword)
This command will return rather or not the mouse button (specified in 'button')
is being pressed. If the button is being pressed the returned value will be 1,
otherwise it will be 0.
POSSIBLE BUTTON VALUES:
0 = LEFT BUTTON
1 = RIGHT BUTTON
2 = MIDDLE BUTTON
3 .. 7 = EXTRA BUTTONS
ms_position x as integer, y as integer
This command will position the mouse at the x/y values specified.
ms_show
This command will show the mouse cursor.
ms_hide
This command will hide the mouse cursor.
ms_update
This command will update the mouse input. Call once every time new
input is required (For example, right before a call to SYNC).
GAME PAD COMMANDS:
gp_setDefault index as dword
This command will set the game pad that is currently getting polled
for input. 0 = 1st, 1 = 2nd, etc.
index as dword = gp_getDefault()
This command will get the game pad index that is currently getting
polled for input. 0 = 1st, 1 =2nd, etc.
x1# as float = gp_getX1()
This command will return what degree the X1 analog is pressed. The
return values are in the range of -1.0 through 1.0.
y1# as float = gp_getY1()
This command will return what degree the Y1 analog is pressed. The
return values are in the range of -1.0 through 1.0.
z1# as float = gp_getZ1()
This command will return what degree the Z1 analog is pressed. The
return values are in the range of -1.0 through 1.0.
x2# as float = gp_getX2()
This command will return what degree the X2 analog is pressed. The
return values are in the range of -1.0 through 1.0.
y2# as float = gp_getY2()
This command will return what degree the Y2 analog is pressed. The
return values are in the range of -1.0 through 1.0.
z2# as float = gp_getZ2()
This command will return what degree the Z2 analog is pressed. The
return values are in the range of -1.0 through 1.0.
state as dword = gp_getState(index as dword)
This command will return rather or not the button specified by the
'index' parameter is being held down (1) or not being held down (0).
gp_update
This command will update all game pad input. Call once every time new
input is required (For example, right before a call to SYNC).
XBOX 360 CONTROLLER COMMANDS:
xb_setDefault index as dword
This command will set the XBox 360 controller to use as the default
polling controller. 0 = 1st, 1 = 2nd, etc. (Up to 4 controllers are
supported).
index as dword = xb_getDefault()
This command will retrieve the XBox 360 controller set as the default
polling controller. 0 = 1st, 1 = 2nd, etc. (Up to 4 controllers are
supported).
connected as dword = xb_isConnected()
This command will retrieve rather or not the current controller is
connected. 1 for connected. 0 for disconnected.
state as dword = xb_getDPadUp()/xb_getDPadRight()/xb_getDPadDown()/xb_getDPadLeft()
These commands will return rather or not the specified directional pad button
is being pressed. 1 for pressed. 0 for not pressed.
extent# as float = xb_getX1()/xb_getY1()/xb_getX2()/xb_getY2()
These commands will return the degree of press on one of the thumb sticks. The 1st
set (X1/Y1) are the left thumb stick. The second set (X2/Y2) are the right thumb
stick. The returned values will range from -1.0 to 1.0.
state as dword = xb_getThumb1()/xb_getThumb2()
These commands will return rather or not the left/right thumb stick is being
pressed down. The returned value will be 1 for pressed or 0 for not pressed.
state as dword = xb_getLeftShoulder()/xb_getRightShoulder()
These commands will return rather or not the left/right shoulders are being
pressed. The returned value will be 1 for pressed or 0 for not pressed.
extent# as float = xb_getLeftTrigger()/xb_getRightTrigger()
These commands will return the extent of press on the left/right trigger. The
returned values will be between 0.0 and 1.0.
state as dword = xb_getStartButton()/xb_getBackButton()/xb_getYButton()/xb_getXButton()/xb_getAButton()/xb_getBButton()
These commands will return rather or not a specific button on the controller
is being pressed or not. The returned value will be 1 for pressed or 0 for
not pressed.
xb_startVibration leftMotorSpeed# as float, rightMotorSpeed# as float, timeInMilliseconds as dword
This command will start vibration in the XBox 360 controller. The vibration's strength is determined
by the speed set for the left and right motors and will last for the duration specified by
timeInMilliseconds which is (big surprise here) a count of milliseconds.
xb_stopVibration
This will stop any previously started vibrations.
xb_update
This will update the XBOX 360 controller input. Call once every time new
input is required (For example, right before a call to SYNC).
Here are some of the example programs:
keyboard test.dba
REM Project: Keyboard Test
REM Created: 8/5/2008 1:54:56 PM
REM
REM ***** Main Source File *****
REM
sync on
sync
disable escapekey
while kb_getKeyState(1) = 0
cls
set cursor 0, 0
print "W = ", kb_getKeyState(17)
print "A = ", kb_getKeyState(30)
print "S = ", kb_getKeyState(31)
print "D = ", kb_getKeyState(32)
print "F = ", kb_getKeyState(33)
print "Backspace = ", kb_getKeyState(14)
kb_update
sync
endwhile
mouse_test.dba
REM Project: Mouse Test
REM Created: 8/5/2008 1:26:54 PM
REM
REM ***** Main Source File *****
REM
sync on
sync
ms_setScreenOn
b_x = 80
b_y = 50
b_w = 100
b_h = 30
dragging = 0
dragX = 0
dragY = 0
do
cls
ink 0xffffffff, 0
x = ms_getX()
y = ms_getY()
mx = ms_getMoveX()
my = ms_getMoveY()
set cursor 0, 0
print "Mouse X = ", x
print "Mouse Y = ", y
print "Mouse Move X = ", mx
print "Mouse Move Y = ", my
if ms_getState(0)
if dragging = 0
if x >= b_x and y >= b_y
if x < b_x + b_w and y < b_y + b_h
dragging = 1
dragX = x - b_x
dragY = y - b_y
endif
endif
endif
else
dragging = 0
endif
if dragging = 1
b_x = x - dragX
b_y = y - dragY
endif
if b_x < 0 then b_x = 0
if b_y < 0 then b_y = 0
if b_x + b_w > screen width() then b_x = screen width() - b_w
if b_y + b_h > screen height() then b_y = screen height() - b_h
box b_x, b_y, b_x + b_w, b_y + b_h, 0xffc9c9c9, 0xff808080, 0xffc9c9c9, 0xff808080
t$ = "Drag Me!"
center text b_x + (b_w / 2), b_y + ((b_h / 2) - (text height(t$)/2)), t$
if ms_getState(0) = 1 then ink 0xff00ff00, 0 `Left click
if ms_getState(1) = 1 then ink 0xff0000ff, 0 `Right click
if ms_getState(2) = 1 then ink 0xffff0000, 0 `Middle click
if ms_getState(3) = 1 then ink 0xffff00ff, 0 `Extra click (1)
if ms_getState(4) = 1 then ink 0xffff8000, 0 `Extra click (2)
if ms_getstate(5) = 1 then ink 0xff0080ff, 0 `Extra click (3)
if ms_getState(6) = 1 then ink 0xffffff00, 0 `Extra click (4)
if ms_getState(7) = 1 then ink 0xff808080, 0 `Extra click (5)
circle x, y, 25
ms_update
xb_update
sync
loop
xb360 test.dba
REM Project: XB Game Pad Test
REM Created: 8/5/2008 2:12:46 PM
REM
REM ***** Main Source File *****
REM
sync on
sync
disable escapekey
while kb_getKeyState(1) = 0
cls
print "XBox 360 Controller Test"
if kb_getKeyState(2) then xb_setDefault 0
if kb_getKeyState(3) then xb_setDefault 1
if kb_getKeyState(4) then xb_setDefault 2
if kb_getKeyState(5) then xb_setDefault 3
print "Current Controller = ", xb_getDefault(), " (Press '1', '2', '3', or '4' to change)"
print "Is Connected? = ", xb_isConnected()
print "DPad->Up = ", xb_getDPadUp()
print "DPad->Right = ", xb_getDPadRight()
print "DPad->Down = ", xb_getDPadDown()
print "DPad->Left = ", xb_getDPadLeft()
print "X1 = ", xb_getX1()
print "Y1 = ", xb_getY1()
print "X2 = ", xb_getX2()
print "Y2 = ", xb_getY2()
print "Thumb1 = ", xb_getThumb1()
print "Thumb2 = ", xb_getThumb2()
print "Left Shoulder = ", xb_getLeftShoulder()
print "Right Shoulder = ", xb_getRightShoulder()
print "Left Trigger = ", xb_getLeftTrigger()
print "Right Trigger = ", xb_getRightTrigger()
print "Start Button = ", xb_getStartButton()
print "Back Button = ", xb_getBackButton()
print "Y Button = ", xb_getYButton()
print "X Button = ", xb_getXButton()
print "A Button = ", xb_getAButton()
print "B Button = ", xb_getBButton()
kb_update
xb_update
sync
endwhile
I just made the plugin today, this morning actually. Everything appears to be working fine.
Anyways, the download is attached if you want to download it. If you don't it's not like this plugin will "save you from death" in your development. There are some advantages to this plugin though.
1. DBP doesn't natively support the XBox 360 controller. This plugin adds XBox 360 controller support.
2. DBP only supports 4 mouse buttons - this plugin supports 8.
3. DBP's MOUSEX and MOUSEY() commands only work if the mouse is inside the window, and they only return the MOUSEX/MOUSEY positions based on where the mouse is on the screen. This plugin will tell you exactly where the mouse is relative to the screen or the window.

4. From what I can tell (though I'm not entirely sure) DBP only supports 1 joystick (I call them gamepads since the ones I have aren't actually sticks). This plugin supports multiple joysticks and up to 32 buttons per joystick (If I recall correctly).
5. DBP doesn't let you set the state of any of the keys (For whatever purpose you may have in regards to this, it might be a useful feature for you). This plugin allows you to fake keyboard input.
Well, to be fair this plugin isn't necessarilly "complete." I didn't put in force-feedback for joysticks and I didn't include a "gp_isConnected" command (Though there's an xb_isConnected command and vibration support for the XB controller). I'm not able to test vibration support either on the XBox 360 controller since I don't have a real XBox 360 controller, rather a crappy one made for the PC that acts as an XBox 360 controller - but it doesn't support vibration (It does have an air conditioner built into it though, and I never liked it when game's made the controllers vibrate anyways (always annoyed the hell out of me)).
There you have it, I believe that's all that needs to be said.
Cheers,
-naota
I'm not a dictator to those that do stuff for me by will. Only those who don't.