What api decls would you use to...

Blitz3D Forums/Blitz3D Programming/What api decls would you use to...

D4NM4N(Posted 2009) [#1]
turn on/off capslock, num and scroll?


Leon Drake(Posted 2009) [#2]
GDI32?


D4NM4N(Posted 2009) [#3]
Hehe after a bit of reading i declsd my own for those that want it. Its just for numlock at the mo but you could easily add the other two:

The Decls:
.lib "kEYLOCKER.dll."
SetNumLock%(numlock_state%): "SetNumLock"


Header:
#ifndef __MAIN_H__
#define __MAIN_H__


#ifdef _MSC_VER
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif

extern "C"
{
 EXPORT int SetNumLock( int state );
}

#endif // __MAIN_H__


CPP:
#include <main.h>
#include <Windows.h>
EXPORT int SetNumLock( int state )
{
    bool bState;
    if (state==0) bState=false; else bState=true;
   BYTE keyState[256];

   GetKeyboardState((LPBYTE)&keyState);
   if( (bState && !(keyState[VK_NUMLOCK] & 1)) ||
       (!bState && (keyState[VK_NUMLOCK] & 1)) )
   {
       // Simulate a key press
       keybd_event( VK_NUMLOCK,
           0x45,
           KEYEVENTF_EXTENDEDKEY | 0,
           0 );

       // Simulate a key release
       keybd_event( VK_NUMLOCK,
           0x45,
           KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
           0);
   }
   if (!keyState[VK_NUMLOCK]) return 1;
   return (1);
}


If you are wondering why i am turning it into ints its because of some stupid marshalling bug on windows.


chi(Posted 2009) [#4]
or...
; user32.decls
;
; api_keybd_event (bVk%, bScan%, dwFlags%, dwExtraInfo%)	: "keybd_event"
; api_GetKeyState% (nVirtKey%)								: "GetKeyState"


Const VK_NUMLOCK = 144
Const KEYEVENTF_KEYUP = 2

Graphics3D 800,500,0,2

cam=CreateCamera()
PositionEntity cam,0,0,-5

cube=CreateCube()

Repeat
	TurnEntity cube,.2,.2,.2
	If MouseHit(1) Then ToggleNumLock()
	RenderWorld
	state=api_GetKeyState(VK_NUMLOCK)
	Text 10,10,"hit left mousebutton to toggle NUMLOCK"
	Text 10,30,"NUMLOCK = "+Str(state)
	Delay 10
	Flip
Until KeyHit(1)
End

Function ToggleNumLock()
	api_keybd_event(VK_NUMLOCK,0,0,0)
	api_keybd_event(VK_NUMLOCK,0,KEYEVENTF_KEYUP,0)
End Function



D4NM4N(Posted 2009) [#5]
Yeah that would have been easier. :)


Guy Fawkes(Posted 2009) [#6]
whats w/ the numlock? LMAO. why not do something constructive, like activate a webcam on a texture, and texture that image to a 3d object like a cube? and do it over tcp/udp so it can be broadcasted in an mmo? ive ALWAYS wanted to do that! :P


Sauer(Posted 2009) [#7]
I gave the same suggestion as Chi over in the BlitzPlus forum, and then came here to see what you had cooked up and thought "oh wow I must be missing something here."


Ginger Tea(Posted 2009) [#8]
whats w/ the numlock? LMAO. why not do something constructive, like activate a webcam on a texture, and texture that image to a 3d object like a cube? and do it over tcp/udp so it can be broadcasted in an mmo? ive ALWAYS wanted to do that! :P


rez
there you go, thats your task for the week :D


jfk EO-11110(Posted 2009) [#9]
Does it also turn on/off the numlock etc. LED? If so, then i could make one of those old msdos days 3-LED-Lights Disco effect thingies. also known as a 3 Monochrome pixel screen extension :). BTW thanks chi and D4NM4N, useful stuff.