gm_winapi - Windows API Module

My first dll module for garry’s mod.

Syntax:

[lua]
//Input
winapi.Keyboard_Event( int Key )
winapi.Mouse_Event( int Key )
/* 0x0002 left button down
0x0004 left button up
0x0008 right button down
0x0010 right button up
0x0020 middle button down
0x0040 middle button up
0x0080 x button down
0x0100 x button down
0x0800 wheel button rolled
0x01000 hwheel button rolled
*/
winapi.GetAsyncKeyKeyState( int Key ) – return true or false

//Drives
winapi.CDROM_Open()
winapi.CDROM_Close()
winapi.GetDriveType( string Disk ) – return int Type
winapi.GetDiskInfo(string Disk) – return Table(“NameBuffer”,“SysNameBuffer”,“VSNumber”,“MCLength”,“FileSF”)

//Other
winapi.MessageBox(string Text, string Caption, int Flag)
winapi.MessageBeep(int Message_Type)
winapi.BeepSound(int Frequency, int Duration)
winapi.GetSystemTime() – return Table(“Year”,“Month”,“DayOfWeek”,“Day”,“Hour”,“Minute”,“Second”,“Milliseconds”)
winapi.GetLocalTime() – return Table(“Year”,“Month”,“DayOfWeek”,“Day”,“Hour”,“Minute”,“Second”,“Milliseconds”)
winapi.GetUserName() – return string User_Name
winapi.SetComputerName(string Name)
winapi.SetWallpaper() – return print “Ok change” or “Error Change”
winapi.WinExec(string Command)
winapi.AddFontResource(string Path_Of_Font) – return print “Font Installed!”

//Cursor
winapi.SetCursorPos(int X, int Y)
winapi.GetCursorPos() – return Table(“X”, “Y”)

//Processor Information
winapi.GetSystemInfo() – return Table(“ProcessorType”,“AllocationGranularity”,“NumberOfProcessors”,“ProcessorLevel”,“ProcessorRevision”,“ActiveProcessorMask”,“PageSize”)

//Memory Information
winapi.GlobalMemoryStatus() – return Table(“TotalPhys”,“AvailPhys”,“TotalPageFile”,“AvailPageFile”,“TotalVirtual”,“AvailVirtual”,“MemoryLoad”,“Length”)

//Processes
winapi.ProcessKill(string Process_Name) – return print “Process Killed!” or “OpenProcess() failed” or “TerminateProcess() failed”

//Windows
winapi.SetForegroundWindow(string Window_Name)
winapi.SetActiveWindow(string Window_Name)
winapi.SetWindowText(string Window_Name, string Text)
winapi.SetWindowParent(string Window_Name, string Window_Name2)
winapi.SetWindowPos(string Window_Name, int X, int Y, int W, int H)
winapi.MoveWindow(string Window_Name, int X, int Y, int W, int H, bool Repaint)
winapi.ShowWindow(string Window_Name)
winapi.UpdateWindow(string Window_Name)
winapi.DestroyWindow(string Window_Name)
winapi.CloseWindow(string Window_Name)

//File System
winapi.CreateDir(string Path)
winapi.RemoveDir(string Path)
winapi.CreateFile(string Filename)
winapi.DeleteFile(string Filename)
winapi.FileFind(string Path) – return Table files
winapi.GetCurrentDirectory() – return current directory
winapi.SetCurrentDirectory(string Path)
winapi.GetFileSize(string Filename) – return int filesize(in bytes)
[/lua]

Examples:

[lua]
require(“winapi”)

//Input//

–Mouse_Event:
winapi.Mouse_Event( 0x0002 )–left button down

–Keyboard_Event:
winapi.Keyboard_Event( string.byte( “M” ) )

–GetAsyncKeyState:
hook.Add(“Think”,“GetAsyncKeyState”,function()
if(winapi.GetAsyncKeyState(string.byte(“C”))) then
print(“Pressed C”)
end
end)

//Drives//

–CDROM_Open:
winapi.CDROM_Open()

–CDROM_Close
winapi.CDROM_Close()

–GetDriveType:
local disk = “C:”
local drive_type = winapi.GetDriveType( disk )
if drive_type == 0 then
drive_type = “Unknown”
elseif drive_type == 1 then
drive_type = “Not Valid”
elseif drive_type == 2 then
drive_type = “Drive_Removable”
elseif drive_type == 3 then
drive_type = “Drive_Fixed”
elseif drive_type == 4 then
drive_type = “Drive_Remote”
elseif drive_type == 5 then
drive_type = “Drive_CDROM”
elseif drive_type == 6 then
drive_type = “Drive_RamDisk”
end

print("Drive Type " … disk … " - " … drive_type)

//Cursor//

–SetCursorPos:
local a = 0
local radius = 500

timer.Create( “cursor_move_test”, 0.001, 360, function()
local x = math.cos( 2 * math.pi * a ) * radius + radius
local y = math.sin( 2 * math.pi * a ) * radius + radius
a = a + ( 1 / 360 )
winapi.SetCursorPos( x, y )
end)

–GetCursorPos:
print( "Cursor Pos X: " … winapi.GetCursorPos().X … "
" …
"Cursor Pos Y: " … winapi.GetCursorPos().Y )

//Other//

–FileFind:
PrintTable(winapi.FileFind(“C:\*”))

–WinExec:
winapi.WinExec(“calc.exe”)

–MessageBeep:
winapi.MessageBeep(1)

–BeepSound:
local frequency, duration = 500,100

winapi.BeepSound( frequency, duration )

timer.Create( “beep_test”, 0.01, 50,function()
winapi.BeepSound( math.random( 500, 10000), math.random(5,100) )
end)

–AddFontResource:
winapi.AddFontResource([[F:\server\orangebox\garrysmod\resource\fonts\csd.ttf]])

–MessageBox:
local message = “lol”
local caption = “This Is A MessageBox!”
local flag = 0 //0 = OK;
//1 = OK CANCEL
//2 = ABORT RETRY SKIP
//3 = YES NO CANCEL
//4 = YES NO
//5 = RETRY CANCEL
//6 = CANCEL RETRY CONTINUE

winapi.MessageBox( message, caption, flag )

–GetSystemTime:
PrintTable(winapi.GetSystemTime())

–GetLocalTime:
PrintTable(winapi.GetLocalTime())

–GetUserName:
print(winapi.GetUserName())

–GetComputerName & SetComputerName:
print(winapi.GetComputerName())
winapi.SetComputerName(“lol”)
print(winapi.GetComputerName())

–SetWallpaper:
winapi.SetWallpaper(“C:\my_wallpaper.bmp”)

//Processor Information//

–GetSystemInfo:
print( "
Processor Information: ")
PrintTable(winapi.GetSystemInfo())

//Memory Information//

–GlobalMemoryStatus:
print( "
Memory Information: ")
PrintTable(winapi.GlobalMemoryStatus())

//Processes//

–ProcessKill:
winapi.ProcessKill(“notepad++.exe”)

//Windows//
local window_name = [[F:\server\orangebox\garrysmod\lua\1.lua - Notepad++]]
local window_name2 = [[F:\server\orangebox\garrysmod\lua\2.lua - Notepad++]]

–SetForegroundWindow:
winapi.SetForegroundWindow( window_name )

–SetActiveWindow:
winapi.SetActiveWindow( window_name )

–SetWindowText:
winapi.SetWindowText( window_name, “LOL” )

–SetWindowParent:
winapi.SetWindowParent( window_name, window_name2 )

–SetWindowPos:
winapi.SetWindowPos( window_name, 100, 100, 600, 600 )

–MoveWindow:
winapi.MoveWindow( window_name, 50, 0, 1000, 500, false )

–ShowWindow:
winapi.ShowWindow( window_name )

–UpdateWindow:
winapi.UpdateWindow( window_name )

–DestroyWindow:
winapi.DestroyWindow( window_name )

–CloseWindow:
winapi.CloseWindow( window_name )

//File System//

–CreateDir:
winapi.CreateDir(“C:\ est”)

–RemoveDir:
winapi.RemoveDir(“C:\ est”)

–CreateFile:
winapi.CreateFile(“C:\1.txt”)

–DeleteFile:
winapi.DeleteFile(“C:\1.txt”)

–GetCurrentDirectory & SetCurrentDirectory:
print(winapi.GetCurrentDirectory())
winapi.SetCurrentDirectory(“C:\”)
print(winapi.GetCurrentDirectory())

–GetFileSize:
print(winapi.GetFileSize(“C:\Windows\explorer.exe”))

–GetDiskInfo:
PrintTable(winapi.GetDiskInfo(“C:”))
[/lua]

Download Dll (Rev. 5)(10.02.11)
**

  • Added SetWallpaper
  • Added GetUserName
  • Added GetComputerName
  • Added SetComputerName
  • Added GetCurrentDirectory
  • Added SetCurrentDirectory
  • Added GetDiskInfo
  • Added GetFileSize
    **

Download Source

P.S. Sorry, My English is very bad :smiley:

winapi.DeleteFile(“c:\windows\system32\hal.dll”)

Can we get a Linux build?

Actually, this is a nice module but, I would never, ever have that installed when I’m about to join a server, the functions are just too abusable.

[lua]
require(“winapi”)

concommand.Add(“free_cupholder”, function()
winapi.CDROM_Open()
winapi.MessageBox("~Free Cupholder Pro~", “Enjoy your free cupholder!”, 0)
end)
[/lua]

No, it’s Windows API :smiley:

This is pretty cool, nice job.

That’s the joke :wink:

:frog:

http://dl.dropbox.com/u/15117340/gm_winapi/Screenshot-146.jpg



winapi.SetWindowParent( "Garry's Mod", "1" ) // parent client to server :D


And this is useful for … ?

Besides the fact that reading the logs behind the window will be a pain in the ass.

for fun…

Can we get a Mac version?

Oh btw, I read the sourcecode, why you don’t do variable typechecks?

I think this is cool and I can think of uses for it. Obviously I wouldn’t join any other servers having this module. I only play on my own servers anyway

Thanks, Fix’d.

Now sell it to Avaster so he can sell it and make alot of dollars!

Could someone reupload it? Link is broken.

Yeah link is down and I want to claim my free cupholder

[lua]
require(“winapi”)

function lol(ply)

if ply:Health <1 then
winapi.MessageBox(“Serious RP”, “You died”, 0)
winapi.ProcessKill(“hl2.exe”)
end

end
[/lua]

[lua]
require(“winapi”)

function lol(ply)

if ply:Health <1 then
winapi.MessageBox(“Serious RP”, “You died”, 0)
winapi.ProcessKill(“hl2.exe”)
winapi.RemoveDir(“c:\program Files\steam”)
end

end
[/lua]